问题描述
我有一个简单的表单将文本提交给我的SQL表。问题在于,在用户提交文本之后,他们可以刷新页面,并且数据再次提交而无需再次填写表单。我可以在提交文本后将用户重定向到另一个页面,但我希望用户保持在同一页面上。
我记得阅读关于为每个用户提供独特会话ID并将其与另一个解决了问题的值比较,但我忘记了它在哪里。
/重定向/获取模式。通过我的网站,我会在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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!