NOTE
This problem somehow happens only with a specific server-side api. Therefore it addresses the wrong problem. I'll not delete it since it have answers and comments.
I'm trying to execute a few ajax requests, do some stuff after each is done and some other stuff after all of them are done, for that I'm using the code below:
let
myarr = [],
myfunc = arg => myarr.push(arg);
$.when(
$.post(myparams).done(myfunc),
$.post(otherparams).done(myfunc),
$.post(yetanother).done(myfunc)
// it comes out with only one arg
).then(e => console.log(myarr));
But when it comes to execute the then block it usually has only executed the done of the first operation, how could I fix that?
I'm sorry if it's a duplicate but honestly I didn't even knew what to search for :/
Comment
I also tried to create my own deferreds where I would execute the ajax and resolve them inside the done block, but that yielded the same results.
Using only done or only then, same.
done, always usethen.done" - why so absolute? The use-case forthenanddoneare not one in the same. What if you only want the callback to occur if the deferred is resolved?doneor onlythendonewherethendoesn't work as well, and given there are too many pitfalls withdoneI recommend to generally avoid it.