Hash tag, query string, and Ajaxified search results [closed]

妖精的绣舞 提交于 2019-12-11 15:23:27

问题


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.

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.

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.

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?


回答1:


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");

You can add support for browsers that do not support it with history.js



来源:https://stackoverflow.com/questions/12918467/hash-tag-query-string-and-ajaxified-search-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!