防止返回按钮显示 POST 确认警报

Prevent Back button from showing POST confirmation alert(防止返回按钮显示 POST 确认警报)
本文介绍了防止返回按钮显示 POST 确认警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个向网页提供一长串参数的应用程序,因此我必须使用 POST 而不是 GET.问题是当页面被显示并且用户点击返回按钮时,Firefox 会显示一个警告:

I have an application that supplies long list of parameters to a web page, so I have to use POST instead of GET. The problem is that when page gets displayed and user clicks the Back button, Firefox shows up a warning:

要显示此页面,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.

由于应用程序的构建方式是返回是一种非常常见的操作,这对最终用户来说确实很烦人.

Since application is built in such way that going Back is a quite common operation, this is really annoying to end users.

基本上,我想按照这个页面的方式来做:

Basically, I would like to do it the way this page does:

http://www.pikanya.net/testcache/

输入内容,提交,然后单击返回按钮.没有警告,它只是返回.

Enter something, submit, and click Back button. No warning, it just goes back.

谷歌搜索我发现这可能是 Firefox 3 中的一个错误,但我想以某种方式得到这种行为,即使他们修复"了它.

Googling I found out that this might be a bug in Firefox 3, but I'd like to somehow get this behavior even after they "fix" it.

我想它可以通过一些 HTTP 标头来实现,但究竟是哪一个?

I guess it could be doable with some HTTP headers, but which exactly?

推荐答案

一种方法是将 POST 重定向到重定向到 GET 的页面 - 请参阅 在维基百科上发布/重定向/获取.

One way round it is to redirect the POST to a page which redirects to a GET - see Post/Redirect/Get on wikipedia.

假设您的 POST 是 4K 的表单数据.大概您的服务器对这些数据做了一些事情,而不是只显示一次然后将其丢弃,例如将其保存在数据库中.继续这样做,或者如果它是一个巨大的搜索表单,请在数据库中创建一个临时副本,几天后或在使用空间限制时基于 LRU 被清除.现在创建可以使用 GET 访问的数据表示.如果它是临时的,则为其生成一个 ID 并将其用作 URL;如果它是一组永久数据,它可能有一个 ID 或可用于 URL 的东西.在最坏的情况下,使用小 URL 之类的算法可以将大 URL 折叠成更小的 URL.重定向 POST 以获取数据的表示形式.

Say your POST is 4K of form data. Presumably your server does something with that data rather than just displaying it once and throwing it away, such as saving it in a database. Keep doing that, or if it's a huge search form create a temporary copy of it in a database that gets purged after a few days or on a LRU basis when a space limit is used. Now create a representation of the data which can be accessed using GET. If it's temporary, generate an ID for it and use that as the URL; if it's a permanent set of data it probably has an ID or something that can be used for the URL. At the worst case, an algorithm like tiny url uses can collapse a big URL to a much smaller one. Redirect the POST to GET the representation of the data.

作为历史记录,这种技术是 1995 年建立的实践.

As a historical note, this technique was established practice in 1995.

这篇关于防止返回按钮显示 POST 确认警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)