如何加载页面每30秒的一部分 [英] How to load a part of page every 30 seconds

查看:144
本文介绍了如何加载页面每30秒的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
   jQuery的Ajax请求每隔30秒

我知道我们可以在某些事件加载页面的一部分。我也知道,我们可以加载整个网页每隔指定的时间。但我想知道如何加载页面的一部分,每30秒。

解决方案

 函数refreshPage(){
    $阿贾克斯({
        网址:AJAX / test.html的,
        数据类型:HTML,
        成功:功能(数据){
            $('。结果')的HTML(数据)。
        },
        完成:函数(){
            window.setTimeout(refreshPage,30000);
        }
    });
}

window.setTimeout(refreshPage,30000);
 

使用的setTimeout 的优点是,如果连接挂起一段时间,你不会得到吨挂起的请求,因为一个新的将只有$ P $后发送pvious一个成品。

Possible Duplicate:
jQuery Ajax request every 30 seconds

I know we can load a part of page on some event. I also know we can load whole web page every specified time. But i wanted to know how to load a part of page every 30 seconds.

解决方案

function refreshPage() {
    $.ajax({
        url: 'ajax/test.html',
        dataType: 'html',
        success: function(data) {
            $('.result').html(data);
        },
        complete: function() {
            window.setTimeout(refreshPage, 30000);
        }
    });
}

window.setTimeout(refreshPage, 30000);

Using setTimeout has the advantage that if the connection hangs for some time you will not get tons of pending requests since a new one will only be sent after the previous one finished.

这篇关于如何加载页面每30秒的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆