1.关于轮询
我的写法:
var time_count = 0; var timer = setInterval(function(){ async.ajax({ url:'', data:'', success:function(data){ if(data.uid && data.uid !== ''){ clearInterval(timer); } } }) time_count++; }, 3000) if (time_count > 20) { clearInterval(timer); }
另外一种写法
checkLogin:{
render:function(callback){
var t = this;
t.callback = callback;
t.loadData(); },
loadData:function(){
var t = this;
t.timer = setTimeout(function(){
async.ajax({
data:'',
url:'',
success:function(data){
if(data.uid && data.uid !=='' ){
t.clearLX();
t.callback && t.callback();
}else{
t.loadData();
}
}
})
}, 3000);
}, clearLX:function(){
var t = this;
clearTimeout(t.timer);
}
}