JQuery将每个与Live相结合

时间:2013-01-14 16:15:10

标签: jquery

我有几个使用Ajax调用更新的div(它是MVC,但HTML完成时看起来像这样):

<div class="progresswrapper running" id = "ProgressWrapper1"></div>
<div class="progresswrapper running" id = "ProgressWrapper2"></div>

然后是javascript:

<script type="text/javascript">
    $(function () {

 var timerid = window.setInterval(function () {
            $('.progresswrapper.running').each(function () {
                 UpdateDivWithDataFromServer();
                 if(I'm done with this div) {
                    $(this).removeClass("running");
                 }
            });
        }, 500);

有可能以某种方式这样做吗?

2 个答案:

答案 0 :(得分:2)

var timerid = window.setInterval(function () {
$('.progresswrapper.running').each(function () {
    UpdateDivWithDataFromServer();
});
}, 500);

$(document).on("ajaxComplete",function(){
    $('.progresswrapper.running').each(function () {
         if(I'm done with this div) {
             $(this).removeClass("running");
         }
    });
});

答案 1 :(得分:1)

您的if()语句需要位于AJAX成功回调中,或者位于.ajaxStop()处理程序内。

var timerid = window.setInterval(function () {
        $('.progresswrapper.running').each(function () {
             UpdateDivWithDataFromServer();
        });
    }, 500);
$('.progresswrapper').ajaxStop(function() {
      $(this).removeClass("running");
});