替换浏览器 url 而不重定向,使用 javascript 当 ajax 调用返回响应

Replace browser url without redirect, using javascript when ajax call return response

本文关键字:javascript ajax 调用 响应 返回 使用 url 浏览器 重定向 替换      更新时间:2023-09-26

我正在寻找在不重新加载页面的情况下替换网址的解决方案。我正在使用无限滚动的javascript插件。当 ajax 调用返回结果时,我想用新的发布网址替换网址。

例如。当前网址:http://example.com/category/

ajax 调用的响应:http://example.com/post-testing/。我想在不重新加载的情况下用the post-testing替换category

我使用了document.location.hashwindow.history.pushState('', '', url);函数,但这些功能不符合要求。

巧它适用于history.pushState(obj,title,url)。所以在你的情况下

history.pushState('','','my_awesome_arl_from_ajax_response');

在他们的环境中不适用于 jsfiddle,但以其他方式工作。