Reputation: 6394
I am doing an ajax request and in the success callback I want to refresh the page to reflect the changes. I am trying to pass parameters to the same page as I refresh that page.
The url is something like:
http://localhost:8080/details#component/12
to which I am appending the parameter as said below.
window.location.href += "?code=approved";
window.location.reload();
The above works in Firefox but not in IE, can you please help here?
Chris.
Upvotes: 4
Views: 26568
Reputation: 10056
if window.location.hash
is empty, you cant assign to location.href a new value without using a correct function (at least tested in chrome).
try the window.location.replace
:
if (!window.location.hash)
{
window.location.replace(window.location.href + "?code=approved")
}
Upvotes: 1
Reputation: 181
The hash is the problem; you append your data to the URL fragment (part after the #) The fragment isn't send to the server, ie the url doesn't change so no need to request the page again. Try manually adding '#some_text' to the url in your browser and see what happens ;)
Try something like this:
var newloc = document.location.href;
if(document.location.hash){
// remove fragment
newloc = newloc.substr(0, newloc.indexOf(document.location.hash));
}
newloc += document.location.search ? ";" : "?"; // prevent double question mark
newloc += 'code=approved';
// append fragment back to url
Upvotes: 1
Reputation: 3956
Try using these for IE:
window.location.reload(false); // To get page from cache
window.location.reload(true); // To get page from server
Upvotes: 1