最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Auto Refresh DIV using JQuery - Stack Overflow

programmeradmin0浏览0评论

My requirement is to auto refresh a DIV every 5 seconds

The DIV content I want to refresh is

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

I also checked some questions on stackoverflow but didn't understand. Please note that I'm using Spring Web MVC. Please suggest.

My requirement is to auto refresh a DIV every 5 seconds

The DIV content I want to refresh is

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

I also checked some questions on stackoverflow but didn't understand. Please note that I'm using Spring Web MVC. Please suggest.

Share Improve this question edited Oct 5, 2015 at 12:57 Luffy 1,3351 gold badge20 silver badges42 bronze badges asked Jul 16, 2013 at 17:27 ronanronan 4,67213 gold badges53 silver badges68 bronze badges 1
  • take a look at setInterval() – A.O. Commented Jul 16, 2013 at 17:29
Add a ment  | 

3 Answers 3

Reset to default 5

This is a jquery question not a spring question since the refresh will be managed on the client.

In jquery, something like this would be appropriate:

$(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
    });
}

You need to create a new view and controller with minimum elements required to be refreshed.

I also faced the same problem and I fixed it by writing a new controller and a view for the div to be refreshed and then used setInterval, actually setTimeout worked better for my requirement. :

setInterval(function(){
    $('#your_div').load('newController');
}, time_interval);
setInterval(function(){
//code here to refresh div
//possibly: document.getElementById("idOfDiv").innerHTML = "new content";
}, 5000);
发布评论

评论列表(0)

  1. 暂无评论