当我的表单中的字段为空白时,我无法理解为什么验证器会显示成功消息。我被引导相信 $.post 在所有字段都得到验证之前不应该运行。我在这里错过了一些简单的东西吗?如果有人能指出我的错误,我将不胜感激。我使用的脚本位于:http: //jqueryvalidation.org/。谢谢
jQuery代码
$(function () {
$.validator.setDefaults ({
errorClass: 'form_error',
errorElement: 'div'
});
$("#BA_boxform").validate({
rules: {
BA_customer: {
required: true
},
customerdept: {
required: true
},
customeraddress: {
required: true
},
BA_service: {
required: true
},
BA_box: {
required: true
},
BA_destdate: {
required: true
},
BA_authorised: {
required: true
}
},
messages: {
BA_customer: {
required: '<br />* required: You must select a customer'
},
customerdept: {
required: "<br />* required: You must select a department"
},
customeraddress: {
required: "<br />* required: You must select a customer address"
},
BA_service: {
required: "<br />* required: You must select a service level"
},
BA_box: {
required: "<br />* required: You must enter a box number for intake"
},
BA_destdate: {
required: "<br />* required: You must enter a destruction date"
},
BA_authorised: {
required: "<br />* required"
}
},
submitHandler: function() {
if ($("#BA_boxform").valid() === true) {
var data = $("#BA_boxform").serialize();
$.post('/domain/admin/requests/boxes/boxesadd.php', data, function() {
}, 'json');
} else
{
return;
}
},
success: function(msg) {
$("#BA_addbox").html("You have entered a box");
//$("#BA_boxform").get(0).reset();
}
});
});