在阅读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.
为什么第二个片段保证前一个间隔已经完成?
我知道第一个(事件循环)但很少混淆第二个片段.
最佳答案
原文链接:https://www.f2er.com/jquery/427766.html