[clug] javascript jquery and long calls

jm jeffm at ghostgun.com
Wed Mar 30 18:28:16 MDT 2011


Well, got it going. Went with the

function waitForMessage(fullUrl, textout) {
     $.ajax({
             url: fullUrl,
                 async: true,
                 cache: false,
                 context: this,
                 success: function(data){
                   textout.append(data);
                   setTimeout(function() {waitForMessage(fullUrl, 
textout)}, 1000);
             }
         });
}

as this make more sense to me and was what I was expecting to see. 
However, every example I saw had

   setTimeout('waitforMessage()', 1000);

assuming that the people writing it were more familiar with javascript 
than I was I tried to modify what they had. I also had a stupid mistake 
which I got correct in the post, but wrong in my code. I had

      this.waitForMessage = waitForMessage();

instead of

    this.waitForMessage = waitForMessage;

those pesky paranthesis make all the difference.

Thanks to all those that replied on- and off-list.

Jeff.

On 31/03/11 10:26 AM, Kevin Pulo wrote:
> Also not sure how the setTimeout would affect things.  You'll probably
> be better off with something like
>
>      setTimeout(function(){waitForMessage(url, textout);}, 1000);
>
> since then the scoping and variable references are more likely to work
> out.
>
> Kev
>



More information about the linux mailing list