搜索结果和后退按钮/ HTML表单 [英] Search Results and the Back Button / HTML Forms

查看:104
本文介绍了搜索结果和后退按钮/ HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上,当用户使用HTML表单进行搜索时,以及我在下一页显示数据库的结果,这是完美的。



但是,当用户点击结果集中的单个记录,然后单击返回在浏览器上,浏览器询问(Firefox):


要显示此页面,Firefox必须发送
重复之前执行
的任何
动作(例如搜索或订单
确认)。




举一个例子,一个搜索DVD收藏的表单,用户每年搜索一次,点击一个单独的电影。当用户点击返回搜索结果页面时,我不希望用户必须重新提交/重新发送该表单数据。



那么是否有人知道如何为了解决这个问题?



为了提供更多信息,我使用POST方法提交表单并使用以下标题停止浏览器缓存页面。

 头文件('Pragma:no-cache'); 
Header(Cache-control:private,no-cache,no-store);
标题(过期:星期一,1997年7月26日05:00:00 GMT);.

由于大多数站点都是密码保护的,所以我不希望密码保护端被缓存,能够在登录后恢复。

从本质上来说,避免这种浏览器行为的最佳方式是什么?原因是什么?是不是缓存的罪魁祸首?我应该在搜索结果页面的页面加载中指定将来几分钟的过期时间吗?



接近这个的最佳方式是什么,不要在其他网站上看到这个问题。我是否在讨论no-cache部分都是错误的?解析方案

你的浏览器是这样做的,因为当用户点击后退浏览器需要重新发布数据才能重新加载页面。解决这个问题的一个方法是使用GET请求而不是POST。在一个GET请求中,表单数据被包含/编码在实际的URL中。



作为一个备注 - 无论使用GET还是POST,都应该考虑是否需要使用会话来缓存结果,以防止不必要的数据库调用。



PS使用GET请求具有很大的优势,即您的搜索结果页面可以加入书签。



编辑:表单,POST / GET请求以及它们之间的差异此处,包括有关发布后重定向模式的信息这解决了这个问题。


I'm looking for a solution to a recurring problem I have with form based search results in my application.

Basically when a user searches using an HTML form and I display the results from the Database on the next page, this works perfectly.

However, when a user clicks on an individual record in the result set and then clicks "Back" on the browser, the browser asks (Firefox):

"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."

To give an example, a form to search a DVD collection, user searches by year, clicks on an individual movie. When the user clicks back to the search results page I don't want the user to have to resubmit/resend that form data.

So does anyone have an idea of how to get around this?

To give you some more information I am using the POST method to submit the form and am using the following headers to stop the browser from caching the page.

Header('Pragma: no-cache');
Header("Cache-control: private, no-cache, no-store");
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");.

As most of the site is password protected, I don't want the password protected side cached and be able to be brought back up after login.

Essentially what is the best way to avoid this type of browser behavior and what is the cause? Is no-cache the culprit? Should I specify an Expire time of a couple of minutes in the future from page load on the search results page?

What is the best way of approaching this as I don't see this problem on other sites. Am I going about the no-cache part all wrong?

解决方案

Your browser is doing this because when the user clicks "back" the browser needs to post the data again in order to reload the page. One way around this is to use a GET request instead of a POST. In a GET request the form data is included/encoded in the actual URL.

As a side note - whether using a GET or POST, you should think about whether you need to use the session in order to cache your results in order to prevent an unnecessary database call.

P.S. Using a GET request has the great advantage that your search results pages will be bookmarkable.

Edit: There's some good info on forms, POST/GET requests and the differences between them here, including info on the "Redirect after Post" pattern which addresses this issue.

这篇关于搜索结果和后退按钮/ HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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