I have an AJAX call which takes care of some server side settings (I'm using this for login, language switches, etc.). If, and only if, server side settings are actually changed as a result of this call, I want to refresh the current page (without reposting POST form data, should we be on a page right after a POST). A simple JS in the callback of the AJAX takes care of this:
window.location.replace( window.location.toString() );
This worked fine, until I started working with anchors. Let's say my URL is something like http://www.mysite.com/index/list#someplace and I do the aforementioned ajax call ending with the window.location.replace
, then nothing happens. The page does not get reloaded. So far tested on FF3.6 and IE7.
reload(true); // Reload the current resources from the browser's cache window. location. reload(); This will reload the page at the current URL from the server.
location. reload() reloads the current page with POST data, while window. location. href='your url' does not include the POST data.
Window location. The replace() method replaces the current document with a new one.
Did you try with:
window.location.hash = ''; //if you want to reload with an empty hash
window.location.reload(true); //reload the page and bypass the cache
We use a single web page for our web app, and some functionality(change in currency, language,...) could trigger a reload.
If you want to prevent some re-post you can use a cookie to prevent the server doing double work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With