following problem - I have to call ajax function number of times, and when all functions are complete, get all results into array. I came up with this:
function doAjax(xx){
var xdata = {json: $.toJSON({name: xx}),
delay: 1};
return $.ajax({
url:"/echo/json/",
data:xdata,
type:"POST"
});
}
var carr = [doAjax('a'),doAjax('b'),doAjax('c'),doAjax('d')]
var result = [];
$.when( carr )
.done(function(data){
console.log(data);
$.each(data, function(ix,val){
console.log(val.name);
});
});
Fiddle here: http://jsfiddle.net/Fkd9n/
All seems to be working fine, the "console.log(data)" writes out the objects with response text, but the "console.log(val.name)" is always "undefined". So how to joint all results in one array once all calls are done?
Thank you!