Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change url on ajax request

I want to add some GET parameters to the page URL. I am loading content like this:

$("#content").load("shop.pl #content .product", $.param({categ:1)}));

How can I change the URL to have the same parameter ?categ=1?

like image 751
bliof Avatar asked Aug 05 '11 11:08

bliof


1 Answers

You can use the HTML5 pushState API to achieve this. However, only the newest browsers support it and IE doesn't even support it yet in IE9. There was no way to do this previsouly. However, there is a convention that you would use location.hash to indicate a page which's state was modified by an ajax request. For more information on how to use url hashes to indicate state on your page you might want to have a look at this.

There is a library, History.js, which can be used for transition to pushState. It's API is very close to the pushState API, but it will transparently provide a hash fragement fallback if the browser does not support pushState.

like image 79
Daniel Baulig Avatar answered Sep 27 '22 19:09

Daniel Baulig