Skip to content

Instantly share code, notes, and snippets.

@cotcotquedec
Created January 19, 2016 07:58
Show Gist options
  • Save cotcotquedec/ebdcaff30739e7f2208e to your computer and use it in GitHub Desktop.
Save cotcotquedec/ebdcaff30739e7f2208e to your computer and use it in GitHub Desktop.
Disable Button during ajax request
$.fn.extend({
// add disabled class to elements
disable: function(state) {
return this.each(function() {
$(this).addClass('disabled');
});
},
// remove class disabled to element
enable: function(state) {
return this.each(function() {
$(this).removeClass('disabled');
});
}
}
jQuery( document ).ajaxSend(function(e) {
jQuery('.btn').disable();
});
jQuery( document ).ajaxStop(function() {
if (jQuery.active == 0) {
jQuery('.btn').enable();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment