I have few ajax methods and I want to execute some code after successful completion of all these ajax calls. I can't alter or redefine the ajax methods. Please let me know , how to achieve this.
I tried with WHEN but it get called immediately and not waiting for all calls to be completed.(As suggested , once I added return in loadData1() , it works fine.)
Now my problem is , if any of the request(loadData1() or loadData2()) is having error then "then()" is not getting executed . Please let me know , how to achieve this.
var load1 = loadData1();
var load2 = loadData2();
var load3 = loadData3();
var load4 = loadData4();
$.when(load1, load2, load3,load4).then(function () {
console.log("All done");
});
function loadData1() {
return $.getJSON("http://10.1.2.3/cgi-bin/GetData1.cgi", function (data) {
console.log(data);
});
}
Thanks