I'd like to use when() to control finishing of multiple AJAX calls such as:
$.when(
$.ajax( "test.aspx" ),
$.ajax( "test2.aspx" ),
...
).then(...);
Finally I would like to use $.when with results of function calls from a variable array. I don't realize how.
How can we correct the next construction? The problem it's incorrect because we pass an array of Function objects, but not results of function calls.
funcArray = [
function() { return $.ajax( "test.aspx" ) },
function() { return $.ajax( "test2.aspx" ) }
]
if( cond )
{
funcArray.push( function() { return $.ajax( "test3.aspx" ) } )
}
$.when.apply( null, funcArray ).then(...); // how to correct here and probably somewhere else?
$.ajax():function() { return $.ajax( "test.aspx" ) }$.whenaccepts promises as its arguments, not functions returning promises. You'll first need to call all your functions, store the returned promises in an array and pass that array to$.when(usingapply).