我正在构建一个相当简单的无限照片页面,它从 Flickr 集合中获取照片。我有以下代码:
$(window).load(function() {
var apiKey = 'XXX';
var userId = 'XXX';
var photoset_id = 'XXX';
$.getJSON('http://api.flickr.com/services/rest/?format=json&method=flickr.photosets.getPhotos&photoset_id=' + photoset_id + '&per_page=1000' + '&page=1' + '&api_key=' + apiKey + '&user_id=' + userId + '&jsoncallback=?', function(data) {
$.each(data.photoset.photo, function(i, FlickrPhoto){
var basePhotoURL = 'http://farm' + data.photos.FlickrPhoto[i].farm + '.static.flickr.com/'
+ data.photos.FlickrPhoto[i].server + '/' + data.photos.FlickrPhoto[i].id + '_' + data.photos.FlickrPhoto[i].secret + ".jpg";
var a_href = "http://www.flickr.com/photos/" + data.photoset.owner + "/" + FlickrPhoto.id + "/";
$("<img/>").attr("src", basePhotoURL).appendTo("#photographs").wrap(("<div class='item'></div>"))
});
});
});
我收到以下错误,我似乎无法弄清楚原因。可能主要失败但没有看到它..
TypeError: data.photos is undefined
[Break On This Error]
...asePhotoURL = 'http://farm' + data.photos.FlickrPhoto[i].farm + '.static.flickr....