2

我有以下代码,验证工作正常,但它不提交

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;
                    }
                }
            });
    }
});

令人难以置信的是它输出到控制台的内容,它让我发疯,它永远迭代,我不得不手动停止它

在此处输入图像描述

4

1 回答 1

2

您需要提交传递给 submitHandler 的表单。您正在通过 jQuery 重新选择表单。请参阅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;
                    }
                }
            });
    }
});
于 2013-09-07T22:13:39.457 回答