哈希标记,查询字符串和Ajaxified搜索结果 [英] Hash tag, query string, and Ajaxified search results

查看:106
本文介绍了哈希标记,查询字符串和Ajaxified搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索表单,当表单中的某些内容更改时,我的Web应用程序会自动发送POST数据。 Web应用程序(用PHP / CodeIgniter编写)接受POST或GET并返回正确的结果并显示在页面上。一切正常。

I have a search form that automatically sends POST data my web application whenever something in the form changes. The web application (written in PHP/CodeIgniter) accepts POST or GET and returns the proper results and displays it on the page. Everything works fine.

现在,我担心的是,URL不反映获取当前搜索结果所需的查询参数。因此,如果有人复制地址并分享,那么点击该网址的用户将看不到预期的数据。与书签标记等相同的问题。

Now, my concern is that the URL does not reflect the query parameters needed to get the current search results. So, if someone copied the address and shared it, the people clicking on that URL won't see the intended data. Same problem with book marking, etc.

可以更新jQuery中的查询字符串,但强制浏览器重定向到新的URL(当它,该页面显示正确的搜索结果,因为Web应用程序实际上最初写入工作非JS)。这种重定向意味着Ajax化的努力被浪费了。

It's possible to update the query string in jQuery, but that forces the browser to redirect to the new URL (which when it does, the page shows the correct search results because the web application was actually originally written to work non-JS). That redirecting means the Ajaxifying efforts were wasted.

似乎像hash#可以用来更新地址,而不使浏览器重定向,但我似乎不能使用非JS情况下的信息(我无法通过GET访问该信息)。

Seems like hash # can be used to update the address without making the browser redirect, but I can't seem to use that information in non-JS situation (I can't access that info via GET).

这个问题应该使用什么方法?

What approach should I be using for this problem?

推荐答案

HTML5浏览器支持历史pushState ,它可以更新浏览器的网址,而不刷新页面。

HTML5 browsers support History pushState which can update the browser's url without refreshing the page.

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");

您可以添加对不支持 history.js

这篇关于哈希标记,查询字符串和Ajaxified搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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