I want to retrieve a value from asynchronous ajax. I came up with the code:
function getInfoChannels(name){
return $.ajax({
url: "https://api.twitch.tv/kraken/channels/" + name,
jsonp: "callback",
dataType: "jsonp"
});
}
var logo;
getInfoChannels(name).done(function(json){
logo = json.logo;
});
console.log('image link from getInfoChannels: '+logo)
which logs image link from getInfChannels: undefined
instead the link.
I'm very new to JS. In my former fun little projects i managed to cramp all my data manipulation inside the .done()
. But this time I want the link to the logo outside of it.