I am using ajax to load my website content and want to update the window location when ajax is successful.
How can I update the window location to "/newpage"?? I need users to be able to go back and to refresh. Is this possible??
Window Location Href The window.location.href property returns the URL of the current page.
replaceState() method The replaceState() is another method that updates the URL without reloading the page. It works exactly the same way as pushState() , but replaces the existing browser history entry instead of adding a new one.
I'm assuming you're using jquery to make the AJAX call so you can do this pretty easily by putting the redirect in the success like so:
$.ajax({
url: 'ajax_location.html',
success: function(data) {
//this is the redirect
document.location.href='/newpage/';
}
});
You can set the value of document.location.href
for this purpose. It points to the current URL. jQuery is not required to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With