Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  180] [ 5]  / answers: 1 / hits: 19048  / 11 Years ago, wed, september 18, 2013, 12:00:00

Ok so I have a form that I am validating with jQuery Validation and I am trying to now submit it with AJAX. With the code below, once the form is valid and you click on submit the page reloads and the inputs are placed in the url address bar (i.e. method=get)



In the ajax method I have that set to POST but it doesn't appear to be using the ajax call.



What did I do wrong?



$().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;
}
});
});

More From » jquery

 Answers
15

Try to use :



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();
}

[#75629] Tuesday, September 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hanna

Total Points: 66
Total Questions: 99
Total Answers: 101

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;