title: polling vs long polling
body: <p>I got onto these <a href="http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery">examples</a> showing polling vs long-polling in javascript, however I do not understand how they differ from one another. Especially regarding the long polling example, how does it keep its connection open?</p>
  
  <p>This is what the traditional polling scenario looks like:</p>
  
  <pre><code>(function poll(){
    setTimeout(function(){
      $.ajax({ url: "server", success: function(data){
        //Update your dashboard gauge
        salesGauge.setValue(data.value);
  
        //Setup the next poll recursively
        poll();
      }, dataType: "json"});
    }, 30000);
  })();
  </code></pre>
  
  <p>and this is the long polling example:</p>
  
  <pre><code>(function poll(){
    $.ajax({ url: "server", success: function(data){
      //Update your dashboard gauge
      salesGauge.setValue(data.value);
  
    }, dataType: "json", complete: poll, timeout: 30000 });
  })();
  </code></pre>
  
  <p>Thanks!</p>