后退按钮重新提交表单数据($ _ POST) [英] Back button re-submit form data ($_POST)

查看:153
本文介绍了后退按钮重新提交表单数据($ _ POST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是后退按钮使浏览器说类似网页过期的时候,previous网页是由表单创建。

例如:


  • 第1页:形式与搜索提交
    指标分析($ _ POST请求的形式
    分2页)

  • 第2页:接收$ _ POST请求,
    显示结果(有链接的用户列表,
    点,第3页)

  • 第3页:显示用户配置文件

现在,当访问者点击它会显示类似网页过期浏览器的后退按钮。

相反,previous页面应该没有任何警告显示(第2页,与用户列表)

如何是你的策​​略来解决这个问题?


解决方案

如果您是与搜索参数提交,您试图获取一些数据,而不是修改一些。

当您想获取一些数据POST时,应使用要创建/修改数据,并获得应使用

所以,你应该使用HTTP GET方法,而不是POST。

结果
或者,如果你有一些创建/修改必须做的操作:


  • 的形式第一柱到第一页

    • 这页做了一些操作的(喜欢写东西到一个数据库)

    • ,然后重定向到另一个页面,使用位置 HTTP标头。


  • 这是最后一页,这是一个使用GET请求由浏览器的查询,显示从URL接收到的参数获取的数据。

查看邮政/重定向/获取维基百科页面,这件事。

My problem is that the back button causes the browser to say something like "Page expired" when the previous page was created by a form.

Example:

  • page1: form submitted with search criterias ($_POST request, form points to page2)
  • page2: Receives $_POST request and show result (list of user with links, points to page3)
  • page3: Show user profile

Now when the visitor clicks the back button in the browser it will show something like "Page expired".

Instead the previous page should be shown with no warnings (page2, with the userlist)

How are your strategies to get around this behavior?

解决方案

If you are submitting a for with search parameters, you are trying to get some data, not modify some.

So, you should use the HTTP GET method, and not POST : POST should be used when you intend to create/modify data, and GET should be used when you intend to fetch some data.


Or, if you have some create/modify operation that has to be done :

  • The form first POSTs to a first page
    • That page does some operations (like writing something to a database)
    • And then redirects to another page, using a Location HTTP header.
  • It's that last page, that's queries by the browser using a GET requests, that displays the data fetched from the parameters received in the URL.

See the Post/Redirect/Get page on wikipedia, about this.

这篇关于后退按钮重新提交表单数据($ _ POST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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