Created
January 19, 2016 07:58
-
-
Save cotcotquedec/ebdcaff30739e7f2208e to your computer and use it in GitHub Desktop.
Disable Button during ajax request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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