我使用jQuery验证插件来验证表单字段。现在我只想在字段有效的情况下发送ajax请求,这意味着在jQuery验证插件成功之后。
JavaScript:
<dependency>
<groupId>com.adobe.xmp</groupId>
<artifactId>xmpcore</artifactId>
<version>5.1.2</version>
</dependency>
$(function(){
$("#form").validate({
errorPlacement: function(label, element) {
label.addClass('arrow');
label.insertAfter(element);
},
wrapper: 'span',
rules: {
email: {
required: true,
email: true
},
name: {
required: true,
minlength: 5
},
password: {
required: true,
minlength: 6
},
rePassword:{
required: true,
minlength: 6,
equalTo: "#password"
},
birthDate:{
required: true
},
aboutYou:{
required: true
}
},
messages:{
email: {
required: "this field is required!",
email: "please enter a valid email!"
},
name:{
required: "this field is required!",
minlength: "name needs to have at least 5 chars!"
},
password:{
required: "password is required!",
minlength: "password needs to have at least 6 chars!"
},
rePassword:{
required: "rePassword is required!",
minlength: "rePassword needs to have at least 6 chars!",
equalTo: "passwords don't match!"
}
}
});
});
答案 0 :(得分:2)
我猜您正在使用以下插件:http://jqueryvalidation.org/documentation/
您正在寻找的可能就是:
submitHandler (default: native form submit)
Type: Function()
Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to submit a form via Ajax after it is validated.
所以你可以做这样的事情
$(".selector").validate({
submitHandler: function(form) {
$(form).ajaxSubmit();
}
});
API文档:http://jqueryvalidation.org/validate
======================
如果那不是您正在使用的插件,请查找以下内容:
“在表单有效时处理实际提交的回调。”在插件API文档中。它肯定会被实现为回调或承诺对象。
答案 1 :(得分:0)
将函数(错误,事件)附加到您的initail验证器插件脚本。
return L