Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Ajax浏览器后退按钮不工作_Jquery_Ajax_Get - Fatal编程技术网

Jquery Ajax浏览器后退按钮不工作

Jquery Ajax浏览器后退按钮不工作,jquery,ajax,get,Jquery,Ajax,Get,在使用ajax和jQuery时,我仍然在努力使用浏览器的历史后退/前进按钮。为了只更改网站上的一个div,我使用以下功能: $(document).on("click",".ajaxLink",function(e){ var hash = jQuery(this).attr('href').split("?")[1]; window.history.pushState("object or string", "my website", "<?php e

在使用ajax和jQuery时,我仍然在努力使用浏览器的历史后退/前进按钮。为了只更改网站上的一个div,我使用以下功能:

$(document).on("click",".ajaxLink",function(e){         
    var hash = jQuery(this).attr('href').split("?")[1];

    window.history.pushState("object or string", "my website", "<?php echo $path, "?"; ?>" + hash);

    $('#content').load("content.php?" + hash);
    return false; // do not follow link
});
$(文档)。在(“单击”、“.ajaxLink”上,函数(e){
var hash=jQuery(this.attr('href').split(“?”)[1];
window.history.pushState(“对象或字符串”、“我的网站”、“哈希”);
$('#content').load(“content.php?”+hash);
返回false;//不跟随链接
});
当使用链接时,它工作正常。但是,单击浏览器的“后退”或“前进”按钮时,只有地址栏中的地址会更改,而内容不会更改。我尝试过一些解决方案,比如Ben Alman的hashchange,不幸的是它们对我不起作用

为了从content.php检索内容,我使用get请求(看起来像content.php?cat=foo)


如果有人能想出一个解决办法,我会非常高兴的

我想你应该看看
popstate
。popstate可能会带来一个解决方案。我尝试了$(window.bind('popstate',函数(event){var hash=window.location;alert(hash);});到目前为止,它会提醒url,但只要我将哈希更改为window.location.split(“?”[1];再也没有什么事情发生了。为什么?请尝试以下操作:
window.location.toString().split(“?”)[1]
使用window.history.pushState(散列,“我的网站”和“+hash);在与jQuery(window).bind组合的click函数中('popstate',函数(event){var hash=event.originalEvent.state;$('content').load(“content.php?”+hash);});成功了吗