每5秒自动刷新一个DIV代码不工作

Auto Refresh a DIV every 5 Seconds code Not working

本文关键字:一个 DIV 代码 工作 5秒 刷新      更新时间:2023-09-26

朋友

我有下面的代码来刷新下面的DIV id refreshDiv,每5秒自动刷新一次,但它不工作

<div id ="refreshDiv" class="span2" style="text-align:left;">
  <c:set var="map" value="${alertStatusForm.channelStateForRecipients[currentChannel]}"></c:set>
<div>
<label><img src="${channelIcon}">&nbsp;
  ${fn:length(map['DELIVERED'])}</label>
 </div>
 <div>
 <label><img src="${channelIcon}">&nbsp;
  ${fn:length(map['FAILED'])}</label>
 </div>
 <div>
<label><img src="${channelIcon}">&nbsp;
${fn:length(map['IN_PROGRESS'])}</label>
</div>
</div>
function refreshDiv(){
     $.ajax({
        url: 'editReg.jsp'
    }).done(function(result) {
        $('#refreshDIV').text(result);
    });
}

您没有调用refreshDiv()。您刚刚定义了它。在加载dom时调用此函数,并在每5秒后使用setTimeout继续调用。

$(function(){
    function refreshDiv(){
        $.ajax({
            url: 'editReg.jsp'
        }).done(function(result) {
            $('#refreshDIV').text(result);
            window.setTimeout(refreshDiv, 5000);
        });
    }
    window.setTimeout(refreshDiv, 5000);
});