Pergunta

I have below 2 questions regarding browser behavior.

  1. When we resend a form using browser's refresh button or F5 key, why does the browser send the post data again when such a behavior isn't desirable (adding to cart the same product again i.e.)?

  2. Why is the post data still being sent when I've clicked "clear your recent history" in FireFox?

Foi útil?

Solução 2

After you do a POST request, browsers keep that information in memory in case they can send it again if you refresh the page. In your case you come from a POST request, so the browser will ask you if you want to send the POST data again, and you cant avoid that.

To avoid it you may add action to the form to a different page and process all the data there.

Or you can process the data on the same page and after processing all the data you can redirect to a new page.

hope this helps..

Outras dicas

Why when we resend a from using browser's refresh button or F5 key the browser sends the post data again while such a behavior isn't desirable (adding to cart the same product again i.e.)?

Because the browser doesn't know it is undesirable. It is being asked to repeat the last request, so it does.

Why the post data is still being send after F5 when I've clicked "clear your recent history" in FireFox?

Because details of how the page was requested are stored in some data structure associated with the current page as well as the history.


If you don't want refreshing the page to repeat a POST request, then use the POST-Redirect-GET pattern.

Respond to the POST request with a 302 redirect. The browser will make a GET request to the URL you are redirecting to. Repeating that request will repeat the GET request, not the POST request.

I think this can give an answer to both the questions:

http://en.wikipedia.org/wiki/Post/Redirect/Get

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top