The strange behavior you see is a limitation of the console and actually has nothing to do with your code.
Resolving object properties is deferred until you expand Object in console . By this time the completed request AJAX and available responseText . However, the value of results[0].responseText immediately resolved as undefined .
If you have done this:
$.when([$.ajax({ url: '/echo/json/', type: 'POST', data: {json: '{"a":12}'} })]).done(function(results) { console.log(JSON.stringify(results[0]));
You will see:
{"readyState": 1} undefined
Instead.
How to solve your problem; I never knew that $.when() accepts arrays, and the documentation doesn't say that. Because of this, when() seems to execute done() immediately, since the array is not deferred (for documents):
If one argument is passed to jQuery.when and it is not deferred, it will be considered as resolved by Deferred, and any attached doneCallbacks files will be executed immediately.
Instead, pass your AJAX requests as separate parameters, as shown in the docs:
$.when($.ajax('a'), $.ajax('b')).done(function (a, b) {
In this way:
$.when($.ajax({ url: '/echo/json/', type: 'POST', data: {json: '{"a":12}'} }), $.ajax({ url: '/echo/json/', type: 'POST', data: {json: '{"b":12}'} })).done(function(a, b) { console.log(a[2].responseText); console.log(b[2].responseText); })β;
There you will receive:
{"a": 12} {"b": 12}
... and updated script: http://jsfiddle.net/39mHw/2/