1 回答

TA貢獻(xiàn)1865條經(jīng)驗 獲得超7個贊
實際上,我認(rèn)為你指的是方法setInterval。我相信你應(yīng)該使用一個初始值為1的計數(shù)器。每次調(diào)用interval方法后,計數(shù)器應(yīng)該增加1,然后你可以檢查計數(shù)器是否超過了值60,然后才進(jìn)行ajax調(diào)用并重新啟動everythink 。
它應(yīng)該看起來像這樣
var counter = 1;
var timer = 0;
yourAjaxCall();
var t = setInterval(function(){
//do client side stuff with time
//after you done check if time needs to be fetched from server {60 seconds passed}
counter++;
if(counter >= 60){
counter = 1;
yourAjaxCall();
}
}, 1000);
function yourAjaxCall(){
$.ajax({
url: 'yoururl',
type: 'post',
success: function(response){
timer = response;
}
});
}
添加回答
舉報