Sam
Sam

Reputation: 1514

Reloading page through javascript: avoid the "Postback" warning

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.

Upvotes: 6

Views: 23953

Answers (6)

kilalile
kilalile

Reputation: 1

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.

Upvotes: 0

Michael
Michael

Reputation: 1267

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

window.location = window.location.href;

Upvotes: 10

weston
weston

Reputation: 2057

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/

Upvotes: 0

mays
mays

Reputation: 397

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.

Upvotes: 2

jensgram
jensgram

Reputation: 31498

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.

Upvotes: 2

balupton
balupton

Reputation: 48709

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

Upvotes: 2

Related Questions