I want to send [1, n) AJAX-requests to the server and after all have returned a result a modal dialog should be closed. $.when(a(), b(), c()) would be perfect, but I don't know how to pass the variable count of functions to $.when as parameter. Any ideas how to solve this problem?
-
related: How do you work with an array of jQuery Deferreds?Bergi– Bergi2014-07-10 23:27:21 +00:00Commented Jul 10, 2014 at 23:27
Add a comment
|
1 Answer
Call the functions and add their return values to an array. Then call $.when passing the array as argument like so:
$.when.apply($, array)
See Function.prototype.apply [MDN] for more information and my answer here for an extended example.
1 Comment
Botic
Sometimes it's just time to knock one's head against the table... JS is too beautiful to get all of it's beauty – .apply() is one of it! Thanks a lot for the "Denkanstoß" ;-)