在阅读Long Polling上的一篇文章时,我对以下两种setInterval之间的问题感到困惑
1 –
setInterval(function(){
$.ajax({ url: "server",success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
},dataType: "json"});
},30000);
2-
(function poll() {
setTimeout(function() {
$.ajax({ url: "server",success: function(data) {
sales.setValue(data.value);
},dataType: "json",complete: poll });
},30000);
})();
根据博客,它说 – 关于第二个片段,
So,this pattern doesn’t guarantee execution on a fixed interval per
se. But,it does guarantee that the prevIoUs interval has completed
before the next interval is called.
为什么第二个片段保证前一个间隔已经完成?
我知道第一个(事件循环)但很少混淆第二个片段.
最佳答案
Why second snippet guarantee that the prevIoUs interval has completed?
原文地址:https://www.jb51.cc/jquery/427766.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。