0

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.

Ricevind
  • 341
  • 1
  • 4
  • 15
  • _" In my former fun little projects i managed to cramp all my data manipulation inside the `.done()`"_ Keep doing that. That's the right way of doing it, or at least call a callback from within `done`. – James Thorpe Mar 30 '16 at 15:21
  • Read the documentation http://api.jquery.com/jquery.ajax/ – Jorge Mejia Mar 30 '16 at 15:21

0 Answers0