I am writing a function which has to get the thumbnail information from a given video using the embed.ly API, however currently the function returns a value before it even g
you can simple use $.getJSON's callback like following:
function result(res) {
console.log(res);
}
function getThumbnail(vUrl) {
var thumbnail = '';
var title = '';
var caption = '';
var content = '';
$.getJSON("http://api.embed.ly/1/oembed?key=:key&url="+vurl, function(data) {
var thumbnail = data.thumbnail_url;
console.log(thumbnail);
var result = {
thumbnail:thumbnail,
vurl:vurl
};
// passing the result to a function
getResult(result);
});
}
NOTE:
You see that I'm calling a function to pass the result, where you are trying to return, but you can't return result to caller function. Because, $.getJSON is asynchronous.