I am trying to access this JSON feed to get the last item in the feed which is the current song playing on the radio station, so I can push it in to a stream player web app:
function getSongData(){
$.ajax({
url: 'http://cjzn.streamon.fm/metadata/recentevents/CJZN-48k.json',
dataType: 'jsonp',
success: function(data) {
var totalItems = data.length;
alert('Current song: ' + data[totalItems].TIT2);
},
error: function() {
alert('Unable to retrieve data');
}
});
}
As you can see I'm using data.length to retrieve the total number of items, which would mean that the number is also the last item in the feed. All I can get is the error message! I understand I need to use JSONP to get the data to my domain, but I honestly don't know if JSONP is supported do that could be the culprit. If so, how else do I get the feed data?
['a', 'b']? What is the highest index in the array?lengthreturned the total number of items. How do I get total number?lengthdoes return the total number of items.['a', 'b']contains two elements, hence.lengthreturns2. The first element has the index0, the second (and last) element has the index1.