[英]Browser's backbutton trouble when using ajax calls
I have a list with search results that is fetched through ajax (to be precise: the microsoft updatepanel). 我有一个包含通过ajax提取的搜索结果的列表(准确地说是Microsoft updatepanel)。 The problem is that I cannot use the backbutton of any webbrowser to navigate back to previous lists that I fetched through ajax.
问题是我无法使用任何Web浏览器的后退按钮导航回我通过Ajax获取的先前列表。 Do you have an idea?
你有想法吗?
Thanks 谢谢
在url中添加一些内容,例如page.html#state1
, page.html#state2
等。这是一种常见的做法
You need to make all the ajax calls update the window.location.hash. 您需要使所有ajax调用都更新window.location.hash。
function getAjaxResource(id) {
// some ajax stuff
window.location.hash = 'resource=' + id;
}
Then you need to add a watcher to the hash with javascript's setInterval function. 然后,您需要使用javascript的setInterval函数将监视程序添加到哈希中。
var hash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != hash) {
hash = window.location.hash;
getAjaxResource(hash.replace('resource=',''));
}
},100);
The hash changes every time the user clicks back/forward and the watcher will pick that change up. 每次用户向后/向前单击时,哈希值都会更改,观察者会选择该更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.