I have a function:
function someFunction(params) {
//Creates an object
//$.each(collection, funct() { /*do work on collection, essentially pushes items into an array */});
//JSON.stringify(results)
//$.ajax POST...this is what I want $.when to wait for
}
I setup
$.when(someFunction(params)
).then(doNextThing);
I also tried
$.when(function() {someFunction(params) }
).then(doNextThing);
doNextThing is invoked before the callback. Is it possible that $.each or stringify is causing $.when to fail?
someFunctionneeds to return an object for$.whento work. Otherwise it is the equivalent ofsomeFunction(params);$.when(undefined).then(doNextThing). In this setupdoNextThingwill never be called.Since you are waiting on the ajax call, it should look something like this: