I have two submit handlers, one validating a form and one submitting the form:
// validates the form but does not submit it
$("form").submit(function() {
// perform validation here and set "validationFails" appropriately
// ...
if (validationFails) {
return false;
}
});
// submits the form via ajax
$("form").submit(function(event) {
event.preventDefault();
// submit the form via ajax here
// ...
});
It seems like the form should not be submitted via ajax if validation fails because return false
is used, and so the subsequent submit
handler in the chain should not be called. However, even if validation fails, the form is submitted via ajax. Why?