Skip to content

Instantly share code, notes, and snippets.

@wonderbeyond
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save wonderbeyond/d29285f966809a3903bd to your computer and use it in GitHub Desktop.

Select an option

Save wonderbeyond/d29285f966809a3903bd to your computer and use it in GitHub Desktop.
Get tick data via jsonp api and update DOM at intervals
/**
* 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