Skip to content

Instantly share code, notes, and snippets.

@pancurster
Created June 30, 2012 15:08
Show Gist options
  • Save pancurster/3024165 to your computer and use it in GitHub Desktop.
Save pancurster/3024165 to your computer and use it in GitHub Desktop.
JS polling
setInterval(function(){
$.ajax({ url: "server", success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
}, dataType: "json"});
}, 30000);
(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);
})();
// LONG POLLING
(function poll(){
$.ajax({ url: "server", success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
}, dataType: "json", complete: poll, timeout: 30000 });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment