Ahmed Fouad
Ahmed Fouad

Reputation: 3073

Is it possible to change URL dynamically when I make $.ajax call?

I do not know if it is possible or no, I use $.ajax to load content via ajax without reloading the page. My url looks like this:

http://localhost/category:blog

I use jQuery $.ajax to load content correctly without reloading, but I need a more functionality than that, I want to set the url in address bar to category:blog after loading via $.ajax, is it possible to run the ajax request when user enters that address directly into browser as well? do I need htaccess or isnt it possible, I am lost in this situation. I just want to make the links like that.

Upvotes: 2

Views: 391

Answers (2)

PHP lover
PHP lover

Reputation: 238

You can use javascript pushState function (http://blog.scoutapp.com/articles/2010/12/07/manipulating-browser-history-with-javascript-pushstate-replacestate) For the second question when the user changes the url I think it's not possible since in unload event(when the user changes the url) you can't stop the brwoser to request the whole page and show it to user And as VisioN said it's not really a good idea to use : in the url

Upvotes: 0

MilMike
MilMike

Reputation: 12831

I asked this years ago here on stackoverflow, you can do this by window.location.hash, but it is only possible for # and not the : character.. :

On - window.location.hash - Change?

Upvotes: 3

Related Questions