'Stop browsers asking to resend form data on refresh

I have a form submission via POST. I submit the form, and all is well, however if I try to reload the new page that the form goes to after submission, I get the "Do you want to resend data" message (Firefox). It might happen in other browsers too, but I'm not sure.

Is there a way to stop this message popping up so I can go ahead and refresh the page? It's not good for production environments - users may submit the same form twice!



Solution 1:[1]

An easy way after response.sendRedirect is to reload the page in this way:

window.location.href = window.location.pathname;

It works for me.

Solution 2:[2]

If the URL does not have any parameter, use this -

window.location = window.location.href + "?rnd=" + Math.random();

Or else use this -

window.location = window.location.href + "&rnd=" + Math.random();

It will work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Mortensen
Solution 2 Peter Mortensen