Created
September 13, 2013 08:34
-
-
Save Nowalon/6548115 to your computer and use it in GitHub Desktop.
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
//there's a couple of ways. My preferred way is to attach a function to the ajaxStart/Stop events on the element itself. | |
$('#loadingDiv') | |
.hide() // hide it initially | |
.ajaxStart(function() { | |
$(this).show(); | |
}) | |
.ajaxStop(function() { | |
$(this).hide(); | |
}); | |
//The ajaxStart/Stop functions will fire whenever you do any ajax calls. |
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
//For jQuery I use | |
jQuery.ajaxSetup({ | |
beforeSend: function() { | |
$('#loader').show(); | |
}, | |
complete: function(){ | |
$('#loader').hide(); | |
}, | |
success: function() {} | |
}); |
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
//Variant: I have an icon with id="logo" at the top left of the main page; a spinner gif is then overlaid on top (with transparency) when ajax is working. | |
jQuery.ajaxSetup({ | |
beforeSend: function() { | |
$('#logo').css('background', 'url(images/ajax-loader.gif) no-repeat') | |
}, | |
complete: function(){ | |
$('#logo').css('background', 'none') | |
}, | |
success: function() {} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment