Sending parameters via url during reload

24,819

Solution 1

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

Solution 2

Try using these for IE:

window.location.reload(false); // To get page from cache
window.location.reload(true); // To get page from server

Solution 3

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")
    } 
Share:
24,819
ChrisOdney
Author by

ChrisOdney

A weary weary Software Developer

Updated on November 14, 2020

Comments

  • ChrisOdney
    ChrisOdney over 3 years

    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.