I have examined all of the similar questions about this issue, but still could not figure out the way it should work. Could anyone lead me in the right direction. data and data2 is not loaded on time but after I skip $.when part in chrome debugger they appear. Thanks in advance.
function First (number) {
return $.ajax({
url: "/…",
data: { 'number': number },
type: "POST",
cache: "False",
success: function (data) {
return data;
},
error: function (xhr, type) {
alert('Something went wrong.')
}
});
}
function Second (number) {
return $.ajax({
url: "/…",
data: { 'number': number },
type: "POST",
cache: "False",
success: function (data2) {
return data2;
},
error: function (xhr, type) {
alert('Something went wrong.')
}
});
}
function DoSomeBusiness(number) {
$.when(First(number), Second(number)).then(function (data, data2) {
var someData = data; // data and data2 is undefined for sometime but right after I pass this line of code they appear correctly but i cannot use them cause they’re not loading on time.
var someData2 = data2;
});
.. do some business
};