这里我使用的是jQuery验证。它工作正常,填写所有表单字段后,我想做Ajax调用,但我无法做到这一点。我收到了错误。我该怎么办?
jQuery(document).ready(function(){
jQuery("#SubmitForm").validate({
rules: {
"address": {
required: true
},
"username": {
required: true
},
"mobileNumber": {
required: true,
number: true,
minlength : 12
},
"userEmailid": {
required: true,
email: true
},
"message": {
required: true
}
},
messages: {
"address": {
required: "Please enter your Location."
},
"username": {
required: "Please enter your Fullname."
},
"mobileNumber": {
required: "Please enter your Mobile Number."
},
"userEmailid": {
required: "Please enter your Email.",
email: "Please enter valid Email."
},
"message": {
required: "Please enter Message."
}
},
/* jQuery.ajax({
type:'POST',
url :"php/submit_hitachiForm.php",
data: jQuery('form#SubmitForm').serialize(),
cache: false,
contentType: false,
processData: false,
success: function(data) {
console.log(data);
if(data == "success"){
$("#success_message").show();
$("#success_message").fadeOut(4000);
}
},
error:function(exception){
alert('Exeption:'+exception);
}
}); */
});
});
答案 0 :(得分:0)
进行所有验证:
$('#SubmitForm).validate({
// validation rules
});
然后初始化验证函数,如:
if($('#SubmitForm).valid())
{
// make ajax() call here
}
答案 1 :(得分:0)
在您的代码中尝试此操作
submitHandler: function() {
/*ajax request*/
}