Stop browsers asking to resend form data on refresh?

html firefox post

51531 просмотра

4 ответа

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.

Does anyone know of 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!

Автор: Bojangles Источник Размещён: 12.11.2019 09:28

Ответы (4)

48 плюса


You need to use the the POST-Redirect-GET pattern.

Make your form respond with a redirect to a GET request.
This way, when the user refreshes the page, it will only re-send the GET.

Автор: SLaks Размещён: 01.12.2010 05:42

9 плюса

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

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

It works for me.

Автор: Merboy Размещён: 06.12.2012 08:10

1 плюс

If 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.

Автор: Ashwin Размещён: 21.10.2014 06:10

0 плюса

It will be a security violation if browsers do that. For ex in credit card processing, the site may charge the user twice.

The only way round is go to address bar and hit enter. It will cause a new request.

Автор: Madhur Ahuja Размещён: 01.12.2010 05:43
Вопросы из категории :