I have an AJAX call pulling a JSONP file, it will give me the data in the console, but when I try to put the results in an array: topics, I am getting an error.
$.ajax({
type: 'GET',
url: 'http://demo.omnigon.com/christian_bovine/nbapulse/json/all.json',
dataType : 'jsonp',
jsonp : "callback",
jsonpCallback: "onDataLoaded",
success : function(data) {
console.log(data);
var topics = [];
$.each(data, function(i, item){
topics.push({
username: item.TopicName,
mentions: item.LastHourCount,
totalcount: item.TotalCount,
daycount: item.LastHourCount
});
});
console.log(topics);
$('#leader').tmpl(topics).appendTo('#top3');
}
});
If I use $.each(data.results, function(i, item) it will display my jQuery template but all the data will be undefined. So I think the problem has to do with that?
This should do the trick, your object looks like this:
So you needed to select the
dataproperty before iterating over the results.Here is a demo: http://jsfiddle.net/YrJXG/