我有以下代码,验证工作正常,但它没有提交
jQuery("#form_driver").validate({
submitHandler: function(form) {
//check if email exists
jQuery.ajax({
type: "POST",
url: "checkmail.php",
data: ({
email: jQuery("#email").val()
}),
cache: false,
success: function(data)
{
if(data == 0) {
alert("Email doesnt exist");
return false;
}else if (data==1){
alert("The Email is already linked to your location!");
return false;
}else if (data==2){
jQuery("#form_driver").submit();
return true;
}
}
});
}
});
令人难以置信的是它输出到控制台, 它让我疯狂,它永远迭代,我不得不手动停止它
答案 0 :(得分:2)
您需要提交传递给submitHandler的表单。您正在通过jQuery重新选择表单。见the api.
请改为尝试:
jQuery("#form_driver").validate({
submitHandler: function(form) {
//check if email exists
jQuery.ajax({
type: "POST",
url: "checkmail.php",
data: ({
email: jQuery("#email").val()
}),
cache: false,
success: function(data)
{
if(data == 0) {
alert("Email doesnt exist");
return false;
}else if (data==1){
alert("The Email is already linked to your location!");
return false;
}else if (data==2){
form.submit();
return true;
}
}
});
}
});