So, if I have multiple Ajax calls, is it possible for each of them to have done
callback and be in a when
then?
?
Asked
Active
Viewed 54 times
-1

Manny Fleurmond
- 362
- 1
- 6
- 18
-
I guess you got to make an individual deferred object for each http://api.jquery.com/jQuery.Deferred/. – loveNoHate Mar 09 '14 at 21:06
2 Answers
3
Yes, of course it's possible. The done
method even returns the promise, so you can simply write
$.when(
$.ajax(…).done(function(r) {
console.log("ajax 1 resolved with", r)
}),
$.ajax(…).done(function(r) {
console.log("ajax 2 resolved with", r)
})
).done(function(r1s, r2s) {
console.log("both ajax requests done");
});

Bergi
- 630,263
- 148
- 957
- 1,375
-
Thanks. Promises and deferred objects take a bit to wrap my mind around. Your answer helped a ton – Manny Fleurmond Mar 11 '14 at 19:22
1
You'd have to set each ajax call as a deferred object and then set the deferred objects to resolved in the .then() method.

VtoCorleone
- 16,813
- 5
- 37
- 51
-
What do you mean by "*set as a deferred object*"? Maybe post a short code example. – Bergi Mar 10 '14 at 10:50