How to change url after success in ajax without page reload

前端 未结 3 1112
孤城傲影
孤城傲影 2020-12-24 02:23

This is the ajax



        
3条回答
  •  被撕碎了的回忆
    2020-12-24 03:11

    You can do this to your success action :

    window.history.pushState("object or string", "Title", "/new-url");
    

    See this post to Modify the URL without reloading the page for a basic how-to.

    Additional Note:

    1. The first parameter is the data we'll need if the state of the web page changes, for instance whenever someone presses the back or forwards button in their browser. Note that in Firefox this data is limited to 640k characters.
    2. title is the second parameter which can be a string, but at the time of writing, every browser simply ignores it.
    3. This final parameter is the URL we want to appear in the address bar.

    It's now available in most "modern" browsers.

提交回复
热议问题