Last active
August 29, 2015 14:08
-
-
Save wonderbeyond/d29285f966809a3903bd to your computer and use it in GitHub Desktop.
Get tick data via jsonp api and update DOM at intervals
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
| /** | |
| * Demo code snip: | |
| * Get tick data via jsonp api and update DOM at intervals | |
| * | |
| * `#market` is the DOM element to update; | |
| * `https://example.com/data.json` is the url to fetch tick data; | |
| * `1000*5` is the time interval for tick. | |
| */ | |
| $('#market').on('_init _tick', function(event) { | |
| console.log('tick'); | |
| var $root = $(this); | |
| $.ajax({ | |
| dataType : "jsonp", | |
| url : "https://example.com/data.json" | |
| }).done(function(data) { | |
| // process data and update DOM | |
| // ... | |
| }).always(function(){ | |
| setTimeout(function(){ | |
| $root.trigger('_tick'); | |
| }, 1000*5); | |
| }); | |
| }).trigger('_init'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment