views:

21

answers:

1

Ok,

I have an ajax call which takes care of some server side settings (I'm using this for log in, language switches...), 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 works just fine, right 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.

+1  A: 

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.

Mic
I'm trying to do something similar. Not one web page, but I'm trying to condense the app I'm writing in only a few pages. It's exactly the same things (currency, language, a log in) that will trigger a reload of the page. However, if I destroy the hash I risk that the user ends up looking a completely different page as the hashes, at the moment, play in important role in de layout (jquery tools tabs history).
Peter
Pressed, enter to quickly, what I wanted to add is, that I don't know how to use a cookie to prevent a re-post and the re-post alert but I'll look into that, thanks for the tip!
Peter
If you don't use `window.location.hash = ''` the hash key remains when you reload.
Mic
Hey Mic, sorry for the slow response, been working on some other stuff. Anyway, but what if I need the hash to stay in place? I currently solved it by using jQuery UI tabs with cookie history instead of hash based history. Which is not a solution at all, only a work around. The problem will pop up again later on in the project for sure.
Peter
And forgot to mention, even if I follow the proposed code, with a hash in the URL, it still doesn't do the reload. Anyways, thanks for the help!
Peter
The natural pattern, is if you use a hash, you don't reload the page, just hide and show some `DIV`. May be late for your project, but that could workaround your problem, as there wouldn't be reloads anymore. Good luck.
Mic