如何防止页面刷新时的表单重新提交(F5 / CTRL + R) [英] How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

查看:179
本文介绍了如何防止页面刷新时的表单重新提交(F5 / CTRL + R)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表单将文本提交给我的SQL表。问题在于,在用户提交文本之后,他们可以刷新页面,并且数据再次提交而无需再次填写表单。我可以在提交文本后将用户重定向到另一个页面,但我希望用户保持在同一页面上。



我记得阅读关于为每个用户提供独特会话ID并将其与另一个解决了问题的值比较,但我忘记了它在哪里。

/重定向/获取模式。 http://en.wikipedia.org/wiki/Post/Redirect/Get

通过我的网站,我会在cookie或session中存储消息,在帖子后重定向,读取cookie / session,然后清除会话的值或cookie变量。


I have a simple form that submits text to my SQL table. The problem is that after the user submits the text, they can refresh the page and the data gets submitted again without filling the form again. I could redirect the user to another page after the text is submitted, but I want users to stay on the same page.

I remember reading something about giving each user a unique session id and comparing it with another value which solved the problem I am having but I forgot where it is.

解决方案

Use the Post/Redirect/Get pattern. http://en.wikipedia.org/wiki/Post/Redirect/Get

With my website, I will store a message in a cookie or session, redirect after the post, read the cookie/session, and then clear the value of that session or cookie variable.

这篇关于如何防止页面刷新时的表单重新提交(F5 / CTRL + R)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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