Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question setTimeout() problem with Ajax

    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.

    Code:
    /* 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.
    Last edited by kashifbhatti; 11-19-2008 at 10:54 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •