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
Post a Comment