0

I am using jquery ajax calls to change content in a div by clicking links, but my url always the same i mean its not changing by clicking the links just content changes.

so i find history.pushStates which helped me to change the url by clicking link, but it does not create history states, i mean back button of my browser is not calling past ajaxcalls.

This is my javascript code.

function PostFunc(id,page,name)
{
$.ajax
({
type: "POST",
url: "doAjax.php",
data: "mode=viewtopic&threadid="+id+"&page="+page,
success: function(msg)
    {
    $("#entrylist").ajaxComplete(function(event, request, settings)
        {
        $("#entrylist").hide().html(msg).fadeIn();
        counter = 0;
        /* TODO : LEARN PUSHSTATES */
        var replaced = name.replace(/ /g,"+");
        history.pushState(null, null,"viewtopic.php?title="+replaced);
        });
    }
});

ye.. my problem is shortly i dont know how to handle pushstates in my jquery code, and all other codes are seem so strange like they are not for ajaxcalls :/

4

1 回答 1

0

您需要跟踪 hashchange 事件并将您的状态推送到 URL 的窗口哈希部分。是关于在动态页面上保留历史的一个很好的讨论。

你也可以发现这篇文章很有帮助。我个人将 hashchange 插件(详细在这里)用于动态页面,它可以很好地保持同步历史记录并支持动态内容的后退/前进按钮。

于 2012-08-21T08:34:20.753 回答