I'm getting vimeo thumbnails from the API and I'm using a jQuery function to append the data to the dom.
I'm trying to access thumb_url outside ajax, so I can return it to jQuery, but it doesn't work.
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"/>');
});
Fiddle: http://jsfiddle.net/gyQS4/2/ help?