在Ajax请求更改网址 [英] Change url on ajax request

查看:118
本文介绍了在Ajax请求更改网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一些 GET 参数添加到页面URL。我加载像这样的内容:

I want to add some GET parameters to the page URL. I am loading content like this:

$("#content").load("shop.pl #content .product", $.param({categ:1)}));

我如何更改URL具有相同的参数?CATEG = 1

推荐答案

您可以使用HTML5的 pushState API 以实现这一目标。但是,只有最新的浏览器支持它和IE竟然不支持它尚未在IE9。有没有办法做到这一点previsouly。但是,你会使用的location.hash来指示的状态是由一个Ajax请求修改的页面的约定。有关如何使用URL更多信息哈希值,表明国家在网页上,你可能想看看的this

You can use the HTML5 pushState API to achieve this. However, only the newest browsers support it and IE doesn't even support it yet in IE9. There was no way to do this previsouly. However, there is a convention that you would use location.hash to indicate a page which's state was modified by an ajax request. For more information on how to use url hashes to indicate state on your page you might want to have a look at this.

有一个库, History.js ,该可用于过渡到pushState。它的API是非常接近的pushState API,但它会透明地提供一个哈希fragement回退,如果浏览器不支持pushState。

There is a library, History.js, which can be used for transition to pushState. It's API is very close to the pushState API, but it will transparently provide a hash fragement fallback if the browser does not support pushState.

这篇关于在Ajax请求更改网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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