Rails:ajax避免多次表单提交
我有一个提交按钮,需要确保在 AJAX 请求完成之前只按下/提交一次。 Javascript 解决方案在 noScript 的情况下并不安全。 Rails 有没有合适的方法来做到这一点?
I have an submit button and need to ensure that is only pressed/submit one time until the AJAX request is finished. The Javascript solutions are not safe in case of noScript.
Is there a propper way to do that in Rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的解决方案是生成一个令牌并将其放置为隐藏的表单字段。提交表单后,转到数据库并将令牌标记为已使用,如果另一个表单提交再次发送相同的令牌,则这是双重提交,您应该对其执行任何您想做的操作。
Simplest solution would be generating a token and placing it as a hidden form field. When the form is submitted, go to the database and mark the token as used, if another form submit sends the same token again, it's a double submit and you should do whatever you would like to do with it.