Skip to content

Instantly share code, notes, and snippets.

@Nowalon
Created September 13, 2013 08:34
Show Gist options
  • Save Nowalon/6548115 to your computer and use it in GitHub Desktop.
Save Nowalon/6548115 to your computer and use it in GitHub Desktop.
//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.
//For jQuery I use
jQuery.ajaxSetup({
beforeSend: function() {
$('#loader').show();
},
complete: function(){
$('#loader').hide();
},
success: function() {}
});
//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