I have successfully created a web application that retrieves data (JSON) from the ebay API and displays it on a chart illustrating the price of each item. The current setup is working well.
However, I am eager to implement real-time updates on the chart whenever an item receives a bid or when an auction ends. All the necessary information is available in the JSON response from ebay.
The challenge I am facing is figuring out how to make the graph update automatically and trigger the ajax call either when the JSON content changes (preferred method) or at regular intervals like every 1 to 5 seconds?
$(function() {
$.ajax({
type: "GET",
url: 'http://open.api.ebay.com/shopping?callname=GetMultipleItems&responseencoding=JSON&appid=&siteid=3&ItemID=350720045158,390524810753,251237014268,200902751277,140927144371&version=811',
dataType: "jsonp",
jsonp: "callbackname",
crossDomain : true,
data: { },
success: function (result) {
arrayOfData = new Array();
var items = result['Item'];
$.each(items, function(i, item) {
var title = items[i]['Title'];
var price = items[i]['ConvertedCurrentPrice']['Value'];
var timeleft = items[i]['TimeLeft'];
arrayOfData.push(['400', title + '<br/><br />' + timeleft]);
});
$('#graph').jqBarGraph({
data: arrayOfData,
height: 800,
width: 1200,
barSpace: 20,
colors: ['#085497','#74b3ea'],
prefix: '£'
});
},
error: function (data) {
console.log(arguments);
}
});
});