Does the counter show during an AJAX request?

What is the best way to display a counter?

I prepared a div (id = "spinner"), which should be visible at boot time.

+5
source share
3 answers

Do you use jQuery?

If you can use:

ajaxStart and ajaxStop: http://docs.jquery.com/Ajax

For example:

$(function(){

    // hide it first
    $("#spinner").hide();

    // when an ajax request starts, show spinner
    $.ajaxStart(function(){
        $("#spinner").show();
    });

    // when an ajax request complets, hide spinner    
    $.ajaxStop(function(){
        $("#spinner").hide();
    });
});

You can customize the melody using the query counter, which increases and decreases if you have many simultaneous requests.

If you are not using jQuery, check out the jQuery source code for which ajaxStart events are actually logged in plain old javascript.

NTN Alex

+8
source

rails. :

$(document).ajaxSend(function(r, s) {
$("#spinner").show();});


$(document).ajaxStop(function(r, s) {
$("#spinner").fadeOut("fast");});
+2
$().ajaxSend(function(r, s) {
    $("#spinner").show();
});

$().ajaxStop(function(r, s) {
    $("#spinner").fadeOut("fast");
});
+1
source

All Articles