I\'m using jquery $.post when submitting a form. I want to disable the button for like 5 seconds after it has been clicked to avoid multiple submission of the form.
Have a look at the .success function here it's what you need.
so what you do is disable button on click
$('#btn').click(function(){
$('#btn').attr('disabled', true);
$.post(base_url + 'folder/controller/function', $('#formID').serialize(), function(data) {
// code on completion here
})
.success(function() {
$('#btn').attr('disabled', false);
})
});
});
This way is better as what happens if your request takes more than 5 seconds to return?