可能重复: 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.
上一篇:查询从HTML文本使用jQuery脚本元素脚本、元素、文本、HTML
下一篇:后xmlHTT prequest发送从PHP $ _ POST访问ArrayBuffer()prequest、xmlHTT、PHP、ArrayBuffer