[英]How to prevent double submission after page refresh
I have a 'contact us' html form and I'm giving gift for each member that click submit.我有一个“联系我们”的 html 表单,我会为每个点击提交的成员赠送礼物。 I want to make sure that a user doesn't submit twice (with different name and email).
我想确保用户不会提交两次(使用不同的姓名和电子邮件)。 I can disable the button after click, but what will be the best solution to prevent submit after page refresh?
单击后我可以禁用该按钮,但是防止页面刷新后提交的最佳解决方案是什么? Thanks
谢谢
Is to directly redirect from your POST
to a GET
request or page.是直接从您的
POST
重定向到GET
请求或页面。 if he/she refreshed it will refresh the other page.如果他/她刷新,它将刷新其他页面。 this is named Redirect After Post and you can read more about it here and in WikiPedia
这被命名为 Redirect After Post,您可以 在此处和WikiPedia 中阅读有关它的更多信息
Two things that you can do and you should do.有两件事你可以做,你应该做。
Submit
button as soon as your client submits the form with valid information in it.Submit
按钮。 So that he/she accidently doesn't send duplicate information in the form.<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
See https://stackoverflow.com/a/45656609/1066234见https://stackoverflow.com/a/45656609/1066234
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.