I have form. There are two inputs:name and birthday. My code is:
<div id="block">
<form role="form" id="addForm" method="post">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter name">
</div>
<div class="form-group">
<label for="birthday">Birthday</label>
<input type="text" class="form-control" id="birthday" required placeholder="Enter birthday">
</div>
<button name="submit" id="submit" value="" type="submit" class="btn btn-large btn-primary btn-block">Add</button>
</form>
</div>
And I validate my form using jquery:
<script>
$().ready(function() {
$("#addForm").validate({
rules:{
name:{
required: true,
minlength: 2,
maxlength: 10,
},
},
highlight: function (element) {
$(element).closest('.form-group').addClass('has-error');
},
messages:{
name:{
required: "This field is required",
minlength: "Name must be at least 2 characters",
maxlength: "Maximum number of characters - 10",
},
},
submitHandler: function(form) {
$(form).ajaxSubmit({
url:'addEmpl.php',
type:'GET',
dataType: 'html',
success: function(data) {
$("#block").html(data);
}
});
}
});
});
</script>
When all inputs are right and I click on button Add my Ajax doesn't work.
Maybe are some wrongs with submitHandler?
You can try this
You can write like this:
Here is the fiddle http://jsfiddle.net/bhumi/bvdu94c4/
Try using the below code instead of ajaxSubmit:
Hope it will help you :)