开发者

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). The problem is that I cannot use the backbutton of any webbrowser to 开发者_如何学运维navigate back to previous lists that I fetched through ajax. Do you have an idea?

Thanks


You need to make all the ajax calls update the 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.

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.


add something to url, like page.html#state1, page.html#state2 etc. It's a common practice

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜