Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 777
Peter Avatar asked Sep 24 '10 15:09

Peter


People also ask

How do I refresh a page using URL?

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.

Does window location href reload the page?

location. reload() reloads the current page with POST data, while window. location. href='your url' does not include the POST data.

What does Window location replace do?

Window location. The replace() method replaces the current document with a new one.


1 Answers

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.

like image 89
Mic Avatar answered Sep 26 '22 15:09

Mic