JQuery Validate: how to check validate completion before ajax submission
I have the Jquery validate plugin working fine when i click on the submit button normally but when I have added the ajax function to the form submit it's submitting the form even though the user is missing some fields that are required. How do I make sure the ajax is run after the validation is completed? I have tried adding the condition to check if the form is valid but it just breaks the ajax submit:
- var ajaxSubmit = function(e) {
-
- // fetch where we want to submit the form to
- if (!$('#abstract_form').valid()) {
- return false;
- }
- var url = $(e).attr('action');
- // fetch the data for the form
- var data = $(e).serializeArray();
- // setup the ajax request
- $.ajax({
- url: url,
- data: data,
- //dataType: 'json',
- success: function(result) {
- $('#response').html(result);
- $('#submit').attr('disabled','disabled');
- },
- error: function(){
- alert('failure');
- }
- });
- e.preventDefault();
- return false;
- }
Any guidance would be greatly appreciated.