title: Which of the following javascripts long polling code should I use?
body: <p>I wanted to use long polling.
  I google it and found many helpful resources, and since many, I am getting confuse which is better.
  Following are three code snippets from two place.</p>
  
  <p><a href="https://gist.github.com/jasdeepkhalsa/4353139" rel="nofollow">https://gist.github.com/jasdeepkhalsa/4353139</a></p>
  
  <pre><code>// Long Polling (Recommened Technique - Creates An Open Connection To Server ∴ Fast)
  (function poll(){
  $.ajax({ 
      url: "server", 
      success: function(data)
               {
              //Update your dashboard gauge
               salesGauge.setValue(data.value);
               }, 
      dataType: "json",
      complete: poll,
      timeout: 30000 
     });
  })();
  
  // The setTimeout Technique (Not Recommended - No Queues But New AJAX Request Each Time ∴ Slow)
  (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><a href="https://github.com/panique/php-long-polling/blob/master/client/client.js" rel="nofollow">https://github.com/panique/php-long-polling/blob/master/client/client.js</a></p>
  
  <pre><code>function getContent(timestamp)
  {
  var queryString = {'timestamp' : timestamp};
  $.ajax(
  {
      type: 'GET',
      url: 'http://127.0.0.1/php-long-polling/server/server.php',
      data: queryString,
      success: function(data){
      // put result data into "obj"
      var obj = jQuery.parseJSON(data);
      // put the data_from_file into #response
      $('#response').html(obj.data_from_file);
      // call the function again, this time with the timestamp we just got from server.php
      getContent(obj.timestamp);
  }
  }
  );
  }
  </code></pre>
  
  <p>My question is which code is long polling best practice?
  Which one should I use?</p>
  
  <p>Thanks in advance.</p>