Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 0.50 KB  |  hits: 3  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Listener on Javascript/Jquery
  2. // just a control var...
  3. var gen = 1;
  4.  
  5. // call the function repeatedly in 5 seconds of interval
  6. // this call returns an id that can be used to stop the calls
  7. var id = setInterval(function(){
  8.  
  9.     // function body...
  10.  
  11.     alert( "making an ajax request...(" + gen + ")" ); // here you call your webservice
  12.     gen++;
  13.  
  14.     // just want to stop it, but you wont need this.
  15.     if ( gen == 10 ) {
  16.         clearInterval( id );
  17.     }
  18.  
  19. }, 5000 ); // 5000 miliseconds == 5 seconds