jquery validate submit form ajax code example

Example 1: submit ajax form validation jquery

$('#form').validate({

    ... your validation rules come here,

    submitHandler: function(form) {
        $.ajax({
            url: form.action,
            type: form.method,
            data: $(form).serialize(),
            success: function(response) {
                $('#answers').html(response);
            }            
        });
    }
});

Example 2: jquey validate and submit form using jquery ajax

$("#form_id").validate({
rules:{
	name:"required",
	email:{email: true,required: true},
	mobile:{required : true,minlength:10},

},

messages: {
	name:"Please fill name",
	email:{email:"Enter Valid Email!",
		required:"Enter Email!"
		},
	mobile:{minlength:"Please enter Valid Mobile No.",
		required:"Please enter Mobile No."
		},
},

submitHandler: function(form){
$.ajax({
	url: form.action,
	type: form.method,
	data: $(form).serialize(),
	success: function(response) {
		$('#answers').html(response);
	}            
      });		
}
});