[英]Using POST method for checkboxes is creating problems on “Reloading/Refreshing” that page
I am using 9 checkboxes to get input from user and using POST method to get the data. 我正在使用9个复选框从用户获取输入,并使用POST方法获取数据。 The problem is that when I try to reload that page, the browser shows me this message-
问题是,当我尝试重新加载该页面时,浏览器显示以下消息:
"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier." “要显示此页面,Firefox必须发送将重复之前执行的任何操作(例如搜索或订单确认)的信息。” with 2 options, RESEND CANCEL.
有2个选项,“取消取消”。 Please tell me what should I do.
请告诉我该怎么办。 Can't use GET as it displays my whole search query.
无法使用GET,因为它显示了我的整个搜索查询。
If you are perform some search to get information, I recommend to just use GET . 如果您正在执行搜索以获取信息,建议您仅使用GET 。 POST-REDIRECT-GET will also display your search query.
POST-REDIRECT-GET还将显示您的搜索查询。
If you use post, the browser will confirm that you really want to do a post once more. 如果您使用发布,浏览器将确认您确实要再次发布。 Use GET to get data, use POST to operate the data, in my personal opinion.
我个人认为,使用GET获取数据,使用POST操作数据。
在我的搜索表单中将方法请求类型从POST更改为GET,并取消了确认框。
Quick and dirty: Store all the values of the check boxes in a $_Session[] array and check for that first. 快速又肮脏:将复选框的所有值存储在$ _Session []数组中,然后首先进行检查。
if($_SESSION["CheckBox1"] === "on")
{
// Do Stuff
}
else
{
// Get $_POST[] Data and do stuff
$_SESSION["CheckBox1"] = $_POST["CheckBox1"];
...
}
When the user submits the Form you first check if the $_SESSION has data otherwise put data in it and go about your normal work. 当用户提交表单时,您首先要检查$ _SESSION是否包含数据,否则请在其中放入数据并进行正常工作。 If a reload happens then the $_SESSION values are used and not the now empty $_POST array.
如果发生重载,则使用$ _SESSION值,而不是现在为空的$ _POST数组。
After posting the data, Redirect to the current page. 发布数据后,重定向到当前页面。 That will cancel out the resend/cancel issue.
这样可以取消重新发送/取消问题。
If your website is User-Profile based, you can have a look at the users data and return selected checked boxes. 如果您的网站基于用户配置文件,则可以查看用户数据并返回选中的复选框。
OR 要么
You can set a cookie value, via javascript [on checkbox click] or backend [when posting], this way you can store checked checkboxes and return it clicked on reload. 您可以通过javascript [在单击复选框时单击]或在后端[在发布时]设置cookie值,这样,您可以存储选中的复选框并在重新加载时单击并返回它。
This only happen when you try to REFRESH page after POST Request. 仅当您尝试在POST请求后刷新页面时,才会发生这种情况。
Bowser asks you what should it do: resend POST data or simply refresh page without POSTING (send GET only). Bowser询问您该怎么做:重新发送POST数据或仅刷新页面而不进行POSTING(仅发送GET)。
The same behaviour on Chrome. Chrome上的行为相同。 Opera doesn't asks, just resend previously sent POST data by default.
Opera不会询问,只是默认情况下重新发送以前发送的POST数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.