views:

43

answers:

3

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??

A: 

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.

elusive
I don't want to redirect them. Just change the url.
If you change the url, you will force the browser to try to request that url server side. You cannot just change the URL in spirit. Best you could do is change the `#hash` part of the url if you use it.
MooGoo
@user - You can't change the URL (except the hash) *without* redirecting them, it would be a huge security issue if you could :)
Nick Craver
As Nick said, this is not possible without redirecting the user. I did not realize, that you wanted to keep the user in place.
elusive
A: 

If you want to use the back button, check this out. http://stackoverflow.com/questions/116446/what-is-the-best-back-button-jquery-plugin

Use document.location.href to change the page location, place it in the function on a successful ajax run.

Capt Otis
A: 

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/';
       }
    });
Munzilla