Question

I'm in a situation where I have an Ajax function making a call to a remote site, saving data into a database, then I want to refresh the current page to show the new data. The problem is I'm also using tabs, so I need to pass #tab6 with the URL to get the visitor back to the correct tab.

I'm using

window.location.href = '/clientarea.php?action=productdetails&id=<?php echo $_POST['pkgid']; ?>#tab6';

as my refresh code. It does appear to change the URL, since after it runs I can see #tab6 on the end of the URL. The problem is it's not actually doing a real refresh of the page data, because it's not showing the new info that's pulled from the remote server. I can see that data after a real refresh.

The hacky option would be to run the window.location.href code to get the anchor in the URL, followed by location.reload(); to get the new data, but I'd like to avoid that if there is a better way to handle it.

Was it helpful?

Solution

You should change something between ? and #.

E.g. you could add/replace a random value just before #, generated with Math.random():

window.location.href = '/clientarea.php?action=productdetails&id=<?php echo $_POST['pkgid']; ?>&random='+Math.random()+'#tab6';

OTHER TIPS

Try

window.location.reload(true);

And hacky solution for chrome

setTimeout(function(){window.location.reload(true);},100)

Instead of window.location.href use window.location.assign.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top