Error (undefined variable) in jQuery
Why is that JSON feed returning an undefined variables while working for other variable? What am I doing wrong or overlooking? Thanks开发者_JAVA技巧.
If you take a look at the contents in response:
curl http://gdata.youtube.com/feeds/users/kaycor/favorites?alt=json-in-script&callback=mycallback
You see that entry.media$group and entry.yt$statistics are not there:
gdata.io.handleScriptLoaded({
"feed": {
// snip ...
"entry": [{
// snip ...
"media$group": {
"media$category": [{
// snip ...
}],
"media$title": {
// snip ...
}
}
}]
}
});
Edit: Not all items contain the media$content
array, so you should modify your each block to something like this:
$.each(data.feed.entry, function(i, item){
var uploader = item['author'][0]['name']['$t'];
if (item['media$group']['media$content']) {
var URL = item['media$group']['media$content'][0]['url'];
var thum = item['media$group']['media$thumbnail'][0]['url'];
}
});
I wrote a quick test script for this and with the if clause in place, it did not throw errors anymore.
精彩评论