简体   繁体   中英

Change url with jquery or plain js

Hi i have written some ajax code where user stays in page www.somedomain.com, inserts some data and ajax brings a response. When response comes, i want url to be changed to www.somedomain.com/response but browser still stays to www.somedomain.com page content. So page will not change but only the url will be slightly different. Also i do not want index.html to be visible in url.

To support older browsers you can use hash navigation:

Keeping history of hash/anchor changes in JavaScript

If you only want it to run on modern browsers you can use the HTML 5 History API.

http://diveintohtml5.info/history.html (Link thanks to Christian Varg)

Obviously you can use HTML5 History API to change the browser URL but in your case you have to change the url on Ajax response so u have to handle Ajax events at client side. ie If you van to change the URL when Ajax response start and change back to original when the Ajax responce end you have to handle two events of Ajax.

  1. OnRequestStart
  2. OnResponseEnd

The first method call at same time your Ajax request start and the second one called when your ajax request become in complete state.
So in this handler method you can change the UL of browser....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM