Created
June 30, 2012 15:08
-
-
Save pancurster/3024165 to your computer and use it in GitHub Desktop.
JS polling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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