1

我的要求是每 5 秒自动刷新一次 DIV

我要刷新的DIV内容是

<div class="row-fluid">
    <div class ="span2">
        <label><spring:message code='total.registration' />:</label>
    </div>
    <div class = "span3">
        ${registrationStatusForm.totalRegis}
    </div>
</div>

我还检查了有关stackoverflow的一些问题,但不明白。请注意,我使用的是 Spring Web MVC。请建议。

4

3 回答 3

5

这是一个 jquery 问题而不是春季问题,因为刷新将在客户端上进行管理。

在 jquery 中,这样的事情是合适的:

$(document).ready(function(){
    setInterval(refreshDiv, 5000); 
}); 

function refreshDiv(){
    $.ajax({
        url: "http://path.to.your/webservice",
        //other stuff you need to build your ajax request
    }).done(function() {
        //update your div
    });
}
于 2013-07-16T17:34:05.077 回答
3

您需要创建一个新的视图和控制器,其中需要刷新的元素最少。

我也遇到了同样的问题,我通过编写一个新的控制器和一个要刷新的 div 的视图来修复它,然后使用 setInterval,实际上 setTimeout 更适合我的要求。:

setInterval(function(){
    $('#your_div').load('newController');
}, time_interval);
于 2013-08-19T09:22:28.653 回答
0
setInterval(function(){
//code here to refresh div
//possibly: document.getElementById("idOfDiv").innerHTML = "new content";
}, 5000);
于 2013-07-16T17:33:12.320 回答