-
-
Save devedatafullstack1/8ba6e3ac6d6b07b391cd31f85204165f to your computer and use it in GitHub Desktop.
Simple Long Polling Example with JavaScript and jQuery by Tian Davis (@tiandavis) from Techoctave.com (http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery)
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
| // Long Polling | |
| (function poll(){ | |
| $.ajax({ url: "server", success: function(data){ | |
| //Update your dashboard gauge | |
| salesGauge.setValue(data.value); | |
| }, dataType: "json", complete: poll, timeout: 30000 }); | |
| })(); |
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
| // 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); | |
| })(); |
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
| // The setInterval Technique | |
| setInterval(function(){ | |
| $.ajax({ url: "server", success: function(data){ | |
| //Update your dashboard gauge | |
| salesGauge.setValue(data.value); | |
| }, dataType: "json"}); | |
| }, 30000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment