I have the following block of code:
$(document).ready(function(){
$("#form").submit(function(ev) {
ev.preventDefault();
$.ajax({
type: "POST",
url: "proxy.php",
data: postData,
success: function(data) {
window.location = "thankyou.php";
},
error:function(xhr, ajaxOptions, thrownError){
console.log(xhr.responseText);
}
});
});
$("#form").validate({
//a bunch of validation here
});
});
The issue is that this will continue to post using ajax even though some validation fails.. why is this? Am I using ev.preventDefault() the wrong way? What I want is that for the form to be validated before I send a POST if some validation fails then just cancel, I believe that is through ev.preventDefault()?
Before doing your ajax request, test if the form is valid:
You may want to try the submitHandler option too: http://docs.jquery.com/Plugins/Validation/validate#options