jqueryvalidation插件与ajax提交处理程序无法正常工作
我在过去几天里使用了jqueryvalidation插件,但还没有使用它与ajax提交。 我所拥有的是下面的两个领域。 提交时,值没有错误。 单击“提交”按钮时,没有任何提交。 它什么都不做。
HTML:
JS:
$('#account-info-form').validate({ // ajax submit submitHandler: function (form) { var $form = $(this); $.ajax({ type: $form.attr('method'), url: $form.attr('action'), data: $form.serialize(), dataType : 'json' }) .done(function (response) { if (response.success == 'success') { alert('success'); } else { alert('fail'); } }); return false; // required to block normal submit since you used ajax } });
没有理由这样做,(并且$(this)
不是你所期望的那样)……
var $form = $(this);
只需使用传递给函数的form
参数即可。
submitHandler: function (form) { $.ajax({ type: $(form).attr('method'), url: $(form).attr('action'), data: $(form).serialize(), dataType : 'json' }) .done(function (response) { if (response.success == 'success') { alert('success'); } else { alert('fail'); } }); return false; // required to block normal submit since you used ajax }