Monday, February 26, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  130] [ 6]  / answers: 1 / hits: 159763  / 15 Years ago, fri, february 20, 2009, 12:00:00

I want to reload a page using:


But I receive the POSTDATA warning because the refresh function want to resend previous POST form data. How can I refresh my page without this warning?

UPDATED: I have no control of the project! I can't workaround the POST itself!

More From » refresh


Just changing window.location in JavaScript is dangerous because the user could still hit the back button and resubmit the post, which could have unexpected results (such as a duplicate purchase). PRG is a much better solution

Use the Post/Redirect/Get (PRG) pattern

To avoid this problem, many web applications use the PRG pattern — instead of returning an HTML page directly, the POST operation returns a redirection command (using the HTTP 303 response code (sometimes 302) together with the HTTP "Location" response header), instructing the browser to load a different page using an HTTP GET request. The result page can then safely be bookmarked or reloaded without unexpected side effects.

Client Side

If you want to do it entirely client side, you'll need to change the browser history before you do the refresh:

if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
window.location = window.location.href;

[#99945] Monday, February 16, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 649
Total Questions: 109
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago