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

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

问题描述

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

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.

我记得读过一些关于为每个用户提供唯一会话 ID 并将其与另一个值进行比较的内容,这解决了我遇到的问题,但我忘记了它在哪里.

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.

推荐答案

使用 Post/Redirect/Get 模式.http://en.wikipedia.org/wiki/Post/Redirect/Get

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

对于我的网站,我会将消息存储在 cookie 或会话中,在发布后重定向,读取 cookie/会话,然后清除该会话或 cookie 变量的值.

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天全站免登陆