2015-06-21 57 views
0

我找到解決方案來替換網址,無需重新加載頁面。我正在使用無限滾動JavaScript插件。當ajax調用返回結果時,我想用新的發佈url替換url。替換瀏覽器網址無重定向,使用JavaScript時,Ajax調用返回響應

例如。 當前網址:http://example.com/category/

由ajax致電:http://example.com/post-testing/。 我想用the post-testing替換category而不用重新加載。

我用document.location.hashwindow.history.pushState('', '', url);功能,但這些都不符合要求。

+0

我可能會很悲觀,但我不認爲你可以在不重新加載頁面的情況下更改URL(你可以使用'#hash',但它不是你想要的)。 –

回答

1

因爲它碰巧與history.pushState(obj,title,url)一起使用。所以在你的情況下

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

不適用於其環境內的jsfiddle,但工作,否則。

相關問題