I'm trying to make several AJAX calls (let's say 2) using promises. Basically I want to be able to merge the two responses together, perform some analysis on them as a whole, then spit out a response. Right now, I have:
var responseArray = [];
for (var i=0; i<letsSayTwo; i++) {
responseArray.push(someAjaxCall(data));
};
responseArray.done(function(response) {
var spit = someAnalysis(response);
console.log(spit);
});
responseArray.fail(function(response) {
console.log('fail');
});
As it stands, I'm getting an "Uncaught TypeError: Object [object Array] has no method 'done'" error in console. Am I correct in thinking that I can't use this method? I looked into using the following bit of code from (http://gregfranko.com/blog/jquery-best-practices/) but I can't seem to get the response that I need.
$.when.apply(this, responseArray).then(function(response) {
console.log(response);
});
Instead, what I get is [response, "success", response] where the first response is the correct return response for one of the AJAX calls and the last response is the actual call itself. How should I go about getting the correct responses from both AJAX calls??
I hope this all makes sense. Thanks!