0

我有几个用 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);

有可能以某种方式做到这一点吗?

4

2 回答 2

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");
         }
    });
});
于 2013-01-14T16:28:42.470 回答
1

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

var timerid = window.setInterval(function () {
        $('.progresswrapper.running').each(function () {
             UpdateDivWithDataFromServer();
        });
    }, 500);
$('.progresswrapper').ajaxStop(function() {
      $(this).removeClass("running");
});
于 2013-01-14T16:22:15.453 回答