Instead of ".each ()" use ".map ()":
var deferreds = $('form.changed').map(function(i, elem) { return $(this).submitWithAjax(); }); $.when.apply(null, deferreds.get()).then(function() { ... });
"$ .when ()" allows you to combine a bunch of pending objects and wait until all of them succeed (or for any failure, note the difference). Usually this allows an arbitrary number of arguments, but since we have an array, I used "apply ()".
Note that I only used this stuff lightly, so read the jQuery API docs to double check :-) edit - also, while re-reading my question, I may have misunderstood you.
Pointy
source share