【发布时间】:2014-01-10 18:59:13
【问题描述】:
我从 API 获取 vimeo 缩略图,并使用 jQuery 函数将数据附加到 dom。
我正在尝试在 ajax 之外访问 thumb_url,所以我可以将它返回给 jQuery,但它不起作用。
function getThumb(vimeoVideoID) {
var thumb_url;
$.ajax({
type: 'GET',
url: 'http://vimeo.com/api/v2/video/' + vimeoVideoID + '.json',
jsonp: 'callback',
dataType: 'jsonp',
success: function (data) {
console.log(data[0].thumbnail_large);
thumb_url = data[0].thumbnail_large;
}
});
return thumb_url;
}
$('.video').each(function () {
var thumb_url = getThumb(this.id);
$(this).append('<img src="' + thumb_url + '" class="video_preview"/>');
});
小提琴:http://jsfiddle.net/gyQS4/2/ 帮忙?
【问题讨论】:
标签: javascript jquery ajax vimeo