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');