Reputation: 91
I am using below java script for contact form submission & after particular time the modal should be closed automatically
if ($('.js-form').length) {
$('.js-form').each(function() {
$(this).validate({
errorClass: 'error form-error',
submitHandler: function(form) {
$.ajax({
type: "POST",
url: "mail.php",
data: $(form).serialize(),
success: function() {
$('#error').modal('hide');
$('#success').modal('show');
},
error: function() {
$('#success').modal('hide');
$('#error').modal('show');
}
});
}
});
});
}
Upvotes: 0
Views: 88
Reputation: 25
To close after a particular time, you have to use setTimeOut. with your current code, the hide/show functionality will execute immediately after the ajax response.
Upvotes: 0
Reputation: 2705
You could use setTimeout()
inside the handlers like this.
success: function() {
$('#error').modal('hide');
$('#success').modal('show');
setTimeout(function(){
$('#success').modal('hide');
}, 3000);
},
error: function() {
$('#success').modal('hide');
$('#error').modal('show');
setTimeout(function(){
$('#error').modal('hide');
}, 3000);
}
Upvotes: 1
Reputation: 833
You need to return false
at the end of submission of your form.
Upvotes: 1