阿贾克斯 - 如何通过内容改变网址 [英] Ajax - How to change URL by content

查看:129
本文介绍了阿贾克斯 - 如何通过内容改变网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来解释一下: 我有一个图片库,第一页 display.php 。 用户可以通过图片使用箭头,当你点击它发送一个Ajax请求来检索数据库的下一张图片箭头翻页。现在我想的网址,以根据显示的画面改变。

I'll explain: I have a picture gallery, the first page is display.php. Users can flip through pictures using arrows, when you click an arrow it sends an Ajax request to retrieve the next picture from the db. Now I want the URL to change according to the picture displayed.

So if the first picture is:
www.mydomain.com/display.php?picture=Paris at night

我会翻转到下一个,网址是

I'll flip to the next one and the URL would be

www.mydomain.com/display.php?picture=The Big Ben

我如何做到这一点?

How do I do this?

推荐答案

这里的技巧是URI的与锚片段。

The trick here are uri's with an anchor fragment.

#点之前的部分到互联网上的资源,并且后通常指定的页面上的锚

The part before '#' points to a resource on the internet, and after normally designates to a anchor on the page.

浏览器不刷新,如果资源是相同的,但移动到锚位时present。

The browser does not refresh if the resource is the same but moves to the anchors position when present.

此方式,您可以保持浏览器历史记录,方便从一个可用性点,同时更换某些部件在页面上使用Ajax的一个快速反应的用户界面。

This way you can keep the convenience of browser history from a usability point of view while replacing certain parts on the page with ajax for a fast and responsive user interface.

使用像jQuery的历史插件(所建议的其他人)真的很容易。你装饰与该插件取剩下的工作rel属性的某些元素

Using a plugin like jQuery history (as suggested by others) is really easy: you decorate certain elements with a rel attribute by which the plugin takes care of the rest.

也有点与此相关的话题是一些所谓的hijax,它的东西我真的很喜欢。

Also kinda related to this topic is something called 'hijax', and it's something I really like.

这意味着生成HTML就像你会在旧时代的AJAX前。然后你劫持喜欢环节某种行为,并要求与阿贾克斯的内容,只更换必要的部分。这种结合上述技术允许真正的搜索引擎友好的和可访问的网页。

This means generating html just like you would in the old days before ajax. Then you hijack certain behavior like links and request the content with ajax, only replacing the necessary parts. This in combination with the above technique allows really SEO friendly and accessible webpages.

这篇关于阿贾克斯 - 如何通过内容改变网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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