There is nothing wrong with your code but the approach is wrong, you are using jQuery validation plugin to validate form and Ajax method call separately, what you could use Ajax method call $.ajax
inside submithandler and the jQuery validate
plugin will invoke the submit handler if the validation has passed.
$('#registration').validate({
rules: {
username: {
minlength: 6,
required: true
},
emailid: {
required: true,
email: true
},
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function(element) {
element
.text('OK!').addClass('valid')
.closest('.control-group').removeClass('error').addClass('success');
},
submitHandler: function(form) {
$.ajax({
type:"POST",
url: "register.php",
data: $(form).serialize(),
}).done(function(data) {
$('#register_alert').append(
'<div class="alert alert-danger text-center">' +
'<button type="button" class="close" data-dismiss="alert">' +
'×</button>' + data + '</div>');
});
}
});