...

View Full Version : setTimeout() problem with Ajax



kashifbhatti
11-19-2008, 09:26 PM
I am showing a count down timer on a web page and using ajax calls to send post back after an interval of 30 secs. The logic is simple but it gets called after every 15 secs.


/* this is the main loop */
this.tick = function() {
try {
var tDate = new Date();
var tDiff = this._timelimit.getTime() - (tDate.getTime() - this.tStart.getTime());

if(!this._isLoaded) {
timerLoadedEvent(this, null);
setTimeout(String(this._manager)+ '.AjaxRequest(\''+this._msgStack.push(tDate)+'|1\')',0);
this._isLoaded=true;
}

/* Check for expiration */
tDate.setTime(tDiff);
this.tickCount++;
if(tDate.getTime()<=this._DATEBASE.getTime()) {
if(this._isRunning) {
timerExpiredEvent(this, null);
if(this._isAjaxActive) setTimeout(String(this._manager)+ '.AjaxRequest(\''+this._msgStack.push(tDate)+'|4\')',0);
this._isRunning=false;
} else { //check for error timer operation
if(!this._isErrorMessageSent && (this._ERRORTIMERTIME >= tDate.getTime())) {
timerErrorExpiredEvent(this,null);
if(this._isAjaxActive) setTimeout(String(this._manager)+ '.AjaxRequest(\''+this._msgStack.push(tDate)+'|5\')',0);
this._isErrorMessageSent=true;
}
}
}


/* Perform AJAX operations */
if(this.tickCount%30==0 && this._isAjaxActive) {
setTimeout(String(this._manager)+ '.AjaxRequest(\''+this._msgStack.push(tDate)+'|'+this._messageToSend+'\')',0);
this._messageToSend='2';
}

/* Queue up the next timer event */
if(this._isAjaxActive && !this._isErrorMessageSent && !this._isStopped) {//if we stop timing without submitting the page, errors could start accumulating on the server side
this.timerID = setTimeout(this.clientID +'_itemTimer.tick()', 1000);
} else if(!this._isAjaxActive && !this._isStopped) {
timerErrorLimitEvent(this,null);
setTimeout(String(this._manager)+ '.AjaxRequest(\''+this._msgStack.push(tDate)+'|7\')',0);//report client fatal error
this.timerID = setTimeout(this.clientID +'_itemTimer.tick()', 1000); //continue looping, but we no longer make AJAX calls
}

} catch(err) {}
}

I cant say there is problem with setTimeout() but using ajax here might have something to do...
Any help in this matter would be appreciated.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum