Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Last active April 17, 2024 10:59

Revisions

  1. Jasdeep Khalsa revised this gist Dec 21, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion longPolling.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Long Polling (Recommened Technique - Creates A Open Connection To Server ∴ Fast)
    // Long Polling (Recommened Technique - Creates An Open Connection To Server ∴ Fast)
    (function poll(){
    $.ajax({ url: "server", success: function(data){
    //Update your dashboard gauge
  2. Jasdeep Khalsa revised this gist Dec 21, 2012. No changes.
  3. Jasdeep Khalsa revised this gist Dec 21, 2012. 3 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion longPolling.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Long Polling
    // Long Polling (Recommened Technique - Creates A Open Connection To Server ∴ Fast)
    (function poll(){
    $.ajax({ url: "server", success: function(data){
    //Update your dashboard gauge
    2 changes: 1 addition & 1 deletion recursivePolling.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // The setTimeout Technique
    // The setTimeout Technique (Not Recommended - No Queues But New AJAX Request Each Time ∴ Slow)
    (function poll(){
    setTimeout(function(){
    $.ajax({ url: "server", success: function(data){
    2 changes: 1 addition & 1 deletion traditionalPolling.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // The setInterval Technique
    // The setInterval Technique (Not Recommended - Creates Queues of Requests ∴ Can Be Slow)
    setInterval(function(){
    $.ajax({ url: "server", success: function(data){
    //Update your dashboard gauge
  4. Jasdeep Khalsa created this gist Dec 21, 2012.
    7 changes: 7 additions & 0 deletions longPolling.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // Long Polling
    (function poll(){
    $.ajax({ url: "server", success: function(data){
    //Update your dashboard gauge
    salesGauge.setValue(data.value);
    }, dataType: "json", complete: poll, timeout: 30000 });
    })();
    11 changes: 11 additions & 0 deletions recursivePolling.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // The setTimeout Technique
    (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);
    })();
    7 changes: 7 additions & 0 deletions traditionalPolling.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // The setInterval Technique
    setInterval(function(){
    $.ajax({ url: "server", success: function(data){
    //Update your dashboard gauge
    salesGauge.setValue(data.value);
    }, dataType: "json"});
    }, 30000);