Twitch tv .when() not working as expected [SOLVED]

Twitch tv .when() not working as expected [SOLVED]
0.0 0


I decided to use the .when to obtain both getJSON objects at once, but despite the data/resutls being successful i could not get the object’s variables like display_name, game, etc. it returns as undefined. it works if i call each one individually, can somebody explain the problem thanks.

$.when($.getJSON(url), $.getJSON(url2)).done(function(listResult, channelResult) {


Promise callbacks in jQuery get passed 3 arguments: 1) The data requested, 2) The status of the request, and 3) the jqXHR object that has a bunch of transactional data. (1) is an array with the data returned from each promise passed to $.when() in order†. So, listResult is actually an array, and channelResult.displayName is undefined. This should get you on the right path:

$.when($.getJSON(url), $.getJSON(url2)).done(function(data) {
    var listResult = data[0],
        channelResult = data[1];
    // Do stuff here

† I can’t find the documentation for this on account of too many margaritas, but I got your example working so I am 100% sure.


Yup that was the error where data returned is not json object but an array with status,object, etc.

Thanks though