我正在嘗試使用Tumblr API實現照片供稿。到目前爲止,它的工作原理與只是文本,但是當我嘗試照片我得到的錯誤Tumblr API:'Can not read property'alt_sizes'of undefined'
Cannot read property 'alt_sizes' of undefined
我不知道如何去糾正我的代碼來解決這個問題。我的代碼是:
$.ajax({
url: "http://api.tumblr.com/v2/blog/myblog.tumblr.com/posts?api_key=key&tag=offers",
dataType: 'jsonp',
success: function(results){
var i = 0;
while (i < 10) {
var type = results.response.posts[i].type;
var date = results.response.posts[i].date;
var link = results.response.posts[i].post_url;
if (type == "photo") {
var photourl = results.response.posts[i].photos[i].alt_sizes[i].url;
$("#tumoffers").append("<div class='tumpost'><a href='" + link + "'><img src='" + photourl + "' alt='" + title + "'/></a></div>");
}
i++;
}//END WHILE
}//END RESULTS FUNCTION
});
在的tumblr的API文檔我看到alt_sizes
轉化爲圖像的大小看,但我不想使用這個屬性。
有誰知道如何讓API忽略這個屬性?