So far I did this:
$.when(Results.ServiceController.Ajax1(clickedNumber))
.then(Results.UtilFunctions.Wait(5000))
.then(Results.ServiceController.Ajax2(clickedNumber));
My Ajax1 function returns ajax object. My Wait function looks like this:
function (time) {
var ret = new $.Deferred();
setTimeout(function () {
ret.resolve();
}, time);
return ret;
}
Problem is that second ajax request funtction (Ajax2) is not waiting for Wait function! Edit: I also tried:
$.when(Results.ServiceController.Ajax1(clickedNumber),Results.UtilFunctions.Wait(5000))
.then(Results.ServiceController.Ajax2(clickedNumber));
and nothing changed. From jQuery documentation:
"In the case where multiple Deferred objects are passed to jQuery.when, the method returns the Promise from a new "master" Deferred object that tracks the aggregate state of all the Deferreds it has been passed. The method will resolve its master Deferred as soon as all the Deferreds resolve, or reject the master Deferred as soon as one of the Deferreds is rejected. If the master Deferred is resolved, it is passed the resolved values of all the Deferreds that were passed to jQuery.when. For example, when the Deferreds are jQuery.ajax() requests, the arguments will be the jqXHR objects for the requests, in the order they were given in the argument list."