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? I开发者_如何学编程f I need to reload the page by another means, so be it.
if you want to refresh the page without including post data and not just postback try
window.location = window.location.href;
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.
The only way would be to stop it from rePOSTing the params. Use
window.location = window.location
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.
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/
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.
精彩评论