Reloading page through [removed] avoid the “Postba

2019-05-07 03:10发布

问题:

I'm triggering a page reload through javascript, using the following:

window.location.reload(true);

However, in some cases (of previous postback), the browser is giving me the following warning "To Display the webpage again, the web browser needs to resend the information you've previously submitted...".

Is there any way of avoing this message and just doing the postback anyway, because this might be confusing for the users? If I need to reload the page by another means, so be it.

回答1:

I don't think there is any way to do a postback without the message when you are doing the reload.

Btw, whats the reload for? If it is for submitting the POST information again, i suggest you manually submit the data through ajax or a hidden form submission using javascript.



回答2:

if you want to refresh the page without including post data and not just postback try

window.location = window.location.href;


回答3:

The request you're trying to do again is a POST request, hence the warning. You can either make sure that you're only reloading resources fetched via GET requests or - alternatively - submit a hidden <form> via the POST method (and thus simulating a reload guaranteed not to be cached).

As you probably already know the warning has to do with idempotence (the lack of side effects) within the HTTP verbs. GET (amongst others) are (should be, at least) considered idempotent, whereas POST requests allow for changes on the server. Therefore, the client should prompt the user to verify that s/he intends to perform the action again.



回答4:

The only way would be to stop it from rePOSTing the params. Use window.location = window.location



回答5:

One way of preserving state data within a page is with fragment identifiers on the url, eg. #filter1, #filter2, and then using the handy hashchange plugin for jQuery to execute code (i.e., reload the relevant part of the page with fresh results) when the url fragment changes via the onhashchange event. It's also nice because the different states can be bookmarked and cached.

http://benalman.com/projects/jquery-hashchange-plugin/



回答6:

After:

mysql_query("insert into table (id_item, quantity, cost) values($m, '$amount', '$cost')");

Put:

header("Location: index.php");

Then reload your page using jquery, and you won't get the "...web browser needs to resend the information..." warning.