Created
January 13, 2012 18:58
-
-
Save fomigo/1608093 to your computer and use it in GitHub Desktop.
How to control 'loading...' process in 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
$(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