好的,我有一个表单,我正在验证jQuery验证,我现在尝试用AJAX提交它。使用下面的代码,一旦表单有效并且您点击提交页面重新加载并且输入被放置在URL地址栏中(即method =“get”)
在ajax方法中,我设置为POST
,但似乎没有使用ajax调用。
我做错了什么?
$().ready(function() {
var $form = $(this);
//validate the inquiry form on keyup and submit
$("#inquiryForm").validate({
showErrors: function(errorMap, errorList) {
for (var error in errorMap) {
$.growl.error({ message: errorMap[error] });
}
},
onkeyup: false,
rules: {
fullName: {
required: true
},
email: {
required: true,
email: true
},
inquiry: {
required: true,
minlength: 5,
maxlength: 500
}
},
messages: {
fullName: "Your name is required",
email: "A valid email address is required",
inquiry: "Your inquiry is required and must have between 5-500 characters"
},
submitHandler: function(form) {
$.ajax({
url: form_submit/inquiry_form/inquiry_form.php,
type: "POST",
data: $(form).serialize(),
success: function(response) {
$('#inquiryFormHolder').html("Your form was submitted!");
}
});
return false;
}
});
});
答案 0 :(得分:8)
尝试使用:
submitHandler: function(form) {
$.ajax({
url: form_submit/inquiry_form/inquiry_form.php,
type: "POST",
data: $(form).serialize(),
success: function(response) {
$('#inquiryFormHolder').html("Your form was submitted!");
}
});
$form.submit();
}