Skip to content

Instantly share code, notes, and snippets.

@pradeepn
Last active December 21, 2015 13:59
Show Gist options
  • Save pradeepn/6316819 to your computer and use it in GitHub Desktop.
Save pradeepn/6316819 to your computer and use it in GitHub Desktop.
Globally add Loading text to the button that post ajax and reset after the request is complete for bootstrap
$(function(){
$(document).on('ajaxSend', function () {
if (settings.context != undefined && settings.context.hasClass('btn')) {
settings.context.button('loading');
}
});
$(document).on('ajaxComplete', function () {
if (settings.context != undefined && settings.context.hasClass('btn')) {
settings.context.button('reset');
}
});
});
//add class 'btn' to the buttton which is the default button class for bootstrap.
//To modify loading message add data-loading-text="custom loading text" in the button html.
//Important! In the ajax call set the "context :$('#btn')" or $(this) if its in click event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment