将消息轮询显示(jquery)。

<script type="text/javascript">
    var _page = 1;
    $(function(){
        show();
        function show(){
            $.getJSON("/message/getMessage?page="+_page,function(data){
                var _arr = new Array();
                for ( var i = data.messages.length;i>0; i-- ) {  
                    _arr.push(data.messages[i-1].content);
                    if(data.messages[i-1].lastPage==1){
                        _page = 0;
                    }
                }
                if(_arr.length>0){$(".message").text(_arr.pop())};
                var _time = setInterval(function(){
                    if(_arr.length>0){
                        $(".message").text(_arr.pop());
                    }else{
                        clearInterval(_time);
                        show();
                    }
                },6000);
                _page = _page + 1;
            });
        }
    });
</script>

相关推荐