Peter
Peter

Reputation: 1211

Using windows.location.replace to refresh page not working with a hash in URL

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.

Upvotes: 5

Views: 13702

Answers (1)

Mic
Mic

Reputation: 25164

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.

Upvotes: 7

Related Questions