通过Ajax提交表单 [英] Submitting form through Ajax

查看:121
本文介绍了通过Ajax提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单-

我正在使用jquery和ajax提交表单.单击该按钮后,数据将提交到数据库.

I am submitting form using jquery and ajax . When the button is clicked the data is submitted to database .

问题-如果用户单击两次提交,则数据库中有两个条目.我该如何解决?

Question - If the user clicks the submit twice there are two entries in the database . how can I solve this ?

我不能使用.one(),因为如果发生错误,则提交按钮将调用验证功能,因此不会提交数据.因此,用户必须再次调用同一功能.

I cannot use .one() because the submit button invokes validation function if the errors happen the data will not be submitted .So , user has to call the same function again .

很明显,我可以使用.success上的变量来执行此操作,但是解决此问题的最佳方法是什么.

Obviously I can do that with a variable on .success .but what is the best solution to this issue .

感谢您的帮助.

推荐答案

覆盖以防止点击是一种方法.

Overlaying to prevent click is one way.

如果您想要一些即插即用的blockUI.js很好.您只需要

If you want something plug and play blockUI.js is good. All you need is

$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);

,或者您可以只使用.ajaxstart().ajaxstop()自己覆盖元素以启用和禁用提交按钮.

or you can just use .ajaxstart() and .ajaxstop() to overlay an element yourself to enable and disable the submit button.

这篇关于通过Ajax提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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