javascript - Jquery Trigger event when JSON .each is done -


i have following code ping list of computers jquery , asp.net.

function ping() {     $('#progress').css("display", "");     $('.comp').each(function () {         var $computer = $(this);                     $.getjson('pingcomputer.aspx', { computer: $(this).attr("rel") }, function (data) {             if (data.status == '1') {                 $($computer).attr("src", "ok.png");             }             else {                 $($computer).attr("src", "nok.png");             }         })     })     $('#progress').css("display", "none"); } 

the pinging works fine. before ping start want make #progress visible (an image) after computers pinged want hide again.

the problem #progress image hidden when function called. how can detect when "pingcomputer.aspx" pages have finished loading?

add counter checks many requests have been completed there started:

function ping() {     $('#progress').css("display", "");     var count = 0,         total = $(".comp").length;     $('.comp').each(function () {         var $computer = $(this);               $.getjson('pingcomputer.aspx', { computer: $(this).attr("rel") }, function (data) {             count++;                  if (data.status == '1') {                 $($computer).attr("src", "ok.png");             }             else {                 $($computer).attr("src", "nok.png");             }             if (count==total) $('#progress').css("display", "none");         })     })  } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -