Why is jQuery's deferred.when
returning promises in the done
callback, rather than their corresponding response data?
var data = {
json: JSON.stringify({
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
}),
delay: 3
};
var firstRequest = $.ajax({
url:'/echo/json/',
data: data,
type: 'POST'
});
var secondRequest = $.ajax({
url:'/echo/json/',
data: data,
type: 'POST'
});
$.when.apply($, [firstRequest, secondRequest]).done(function(data1, data2){
console.log(data1); // returns array, I expect a response object
console.log(data2);
});
Both the documentation and various answers on SO, like this, implies that I should get the actual response objects, rather than arrays with [responseobject, textstatus, jqxhr]
.