我正在尝试使用 jQuery validate 插件验证此表单,但是一旦发现错误它就不会停止 javascript 代码,因此将表单发送到数据库,然后才显示错误。我能做些什么来正确链接这些事件?
$("#salvar-cur").live("click", function () {
var validator = $("#frm_curriculo").validate({
rules: {
cur_nome: {
required: true
}
//other options
},
messages: {
cur_nome: {
required: "*"
}
//other options
}
});
if (validator.numberOfInvalids() == 0) {
alert("Success!")
var params = $("#frm_curriculo").serialize();
$.ajax({
type: "POST",
url: "controller/ctrl_curriculo.php",
data: "acao=inserir&" + params,
dataType: "html",
contentType: "application/x-www-form-urlencoded",
success: function () {
$("#frm_curriculo")[0].reset();
}
});
}
});