阿贾克斯寻呼 - 启用后退按钮 [英] Ajax Paging - Enable Back Button

查看:100
本文介绍了阿贾克斯寻呼 - 启用后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  如何:后退按钮的支持和ldquo;阿贾克斯”的

我有一个ASP.NET MVC实现中,我得到的局部视图通过jQuery的东西,如分页和过滤。现在的问题是,虽然我这样做打破了浏览器的后退按钮。我怎样才能恢复背面按钮的行为(使用英镑改写无刷新的网址是什么?不知道该怎么做,虽然,以及如何在触发后退按钮来重新获取数据。)

I have a ASP.NET MVC implementation in which I get partial views via jQuery for things such as paging and filtering. The problem is though that I break the browser's back button by doing so. How can I restore back button behavior (rewrite the URL without refresh using pound? Not sure how that works though, and how to re-fetch data when the back button is triggered.)

感谢您的帮助!

推荐答案

如你所知,JavaScript的传呼杀死了后退按钮。但它也杀死链接到一个特定网页的能力。为了避免刷新页面,并保持后退按钮,你将需要在URL中使用#。然后,你就可以使用返回按钮(和直接链接到一个网页),但你将需要解析URL页面加载时,页面移动到正确的。

As you know, javascript paging kills the back button. But it also kills the ability to link to a given page. To avoid page reloading, but maintain the back button, you are going to need to use # in the URL. Then you will be able to use the back button (and link directly to a page), but you are going to need to parse the URL when the page loads, moving the page to the correct one.

编辑:

获取的网址:

var baseURL = location.href.slice(0, location.href.indexOf('#'));

然后添加到URL您的新资源:

Then add to the URL with your new resource:

location.href = baseURL + '#page2';
//you'll probably want to figure out the page number programatically

但不要忘记去正确的资源负载:

But don't forget going to the right resource on load:

$(goToResource);
function goToResource() {
    var hashURL = location.href.slice(location.href.indexOf('#'));
    //you AJAX code to load the resource goes here
}

当然,你也许可以找到一个插件来做到这一切给你。

Of course, you could probably find a plugin to do this all for you.

这篇关于阿贾克斯寻呼 - 启用后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆