jQuery,简单的轮询示例 [英] jQuery, simple polling example
本文介绍了jQuery,简单的轮询示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习jQuery,并且试图找到一个简单的代码示例,该示例将轮询API以查找条件. (即每隔几秒钟请求一个网页并处理结果)
I'm learning jQuery, and I'm trying to find a simple code example that will poll an API for a condition. (ie, request a webpage every few seconds and process the results)
我熟悉如何在jQuery中进行AJAX,我只是似乎找不到找到使其在计时器"上执行的正确"方法.
I'm familiar with how to do AJAX in jQuery, I just can't seem to find the "proper" way of getting it to execute on a "timer".
推荐答案
function doPoll(){
$.post('ajax/test.html', function(data) {
alert(data); // process results here
setTimeout(doPoll,5000);
});
}
这篇关于jQuery,简单的轮询示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文