Skip to content

Instantly share code, notes, and snippets.

@fomigo
Created January 13, 2012 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fomigo/1608093 to your computer and use it in GitHub Desktop.
Save fomigo/1608093 to your computer and use it in GitHub Desktop.
How to control 'loading...' process in Ajax request
$(document).ready(function () {
/*************** FIRST EXAMPLE *********************/
$.ajaxSetup({
beforeSend: function() {
$('#general-ajax-load').fadeIn();
},
complete: function() {
$('#general-ajax-load').fadeOut();
},
success: function() {
$('#general-ajax-load').fadeOut();
},
error: function(message) {
alert(message);
}
});
/***************** SECOND EXAMPLE **********************/
$('#loading')
    .hide()
    .ajaxStart(function() {
$(this).show();
    })
    .ajaxStop(function() {
        $(this).hide();
    });
/*** Using jQuery for Ajax loading indicator ***/
$(".loadingIndicator").ajaxStart(function() {
$(this).fadeIn();
}).ajaxComplete(function() {
$(this).fadeOut();
});
/*** jQuery Pocket Reference ***/
$("#loading_animation").bind({
ajaxStart: function() { $(this).show(); },
ajaxStop: function() { $(this).hide(); }
});
}); // end ready function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment