Wait for async ajax requests to finish although both async true












0















I need to wait for all Ajax request to be done before I execute the next although both async true
and I don't want to make async false because i want loader to be showen, here's my code



$('#RequestDetails_VacationPeriod').blur(function () {



        AddPeriodToDate();

ShowSickLeavesDistributionInfo(null);

});


function AddPeriodToDate() {



        var employeeNumber = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var periodValue = parseInt($("#RequestDetails_VacationPeriod").val());
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();
var totalLeavePeriodsUnderProcessing = $("#RequestDetails_TotalLeavePeriodsUnderProcessing").val();

if (vacationStartDate && periodValue && vacationTypeSelectedVal) {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/AddPeriodToDate",
async: true,
data: {
"employeeNumber": employeeNumber,
"vacationStartDate": vacationStartDate,
"periodValue": periodValue,
"totalLeavePeriodsUnderProcessing": totalLeavePeriodsUnderProcessing,
"decisionTypeNumber": vacationTypeSelectedVal
},
cache: true,
contentType: "application/json; charset=utf-8",
contentType: "json",
success: function (result) {

$(".loader").fadeOut();
$("#RequestDetails_VacationEndDate").val(result.VacationEndDate);

$("#RequestDetails_RemainingBalance").val(result.objVacationRequestDetail.RemainingBalance);

var remainingBalanceVal = parseInt($("#RequestDetails_RemainingBalance").val());

if (periodValue >= remainingBalanceVal) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_RemainingBalance').addClass("md-show");

return false;
} else {
$('#Modal_RemainingBalance').removeClass("md-show");

return true;
}

$("#RequestDetails_RemainigAnnualDays").val(result.objVacationRequestDetail.RemainigAnnualDays);
$("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing);
$("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing);

var remainingBalanceAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val();
var remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val();

if (parseInt(periodValue) > parseInt(remainingBalanceAfterDeductingLeavesPeriodUnderProcessing) ||
parseInt(periodValue) > parseInt(remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing)) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').addClass("md-show");

return false;

} else {
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').removeClass("md-show");

return true;
}
}
});
}
}


function ShowSickLeavesDistributionInfo(e) {



    var employeeNo = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var vacationPeriod = $("#RequestDetails_VacationPeriod").val();
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();

if ($(e) && $(e).attr("id") == "btn-Control") {

var sickLeavesDistributionRequiredMessage = "";

if (vacationTypeSelectedVal === "") {
ReadFromResources("Ksu_SickLeavesDistributionVacationsystemCodeGroupReuired");
sickLeavesDistributionRequiredMessage = resourceValue + " ,";
}

if (vacationStartDate === "") {

ReadFromResources("Ksu_SickLeavesDistributionVacationStartReuired");
sickLeavesDistributionRequiredMessage += resourceValue + " ,";
}

if (vacationPeriod === "") {
ReadFromResources("Ksu_SickLeavesDistributionvacationPeriodReuired");
sickLeavesDistributionRequiredMessage += resourceValue;
}

if (sickLeavesDistributionRequiredMessage) {

var lastChar = sickLeavesDistributionRequiredMessage.substr(sickLeavesDistributionRequiredMessage.length - 1);

if (lastChar === ",") {
sickLeavesDistributionRequiredMessage = sickLeavesDistributionRequiredMessage.slice(0, -1);
}

$(".SickLeavesDistributionParametersRequired").html(sickLeavesDistributionRequiredMessage);
$('#Modal_SickLeavesDistributionParametersRequired').addClass("md-show");

return false;
} else {
$('#Modal_SickLeavesDistributionParametersRequired').removeClass("md-show");

return true;
}
}

if (vacationStartDate && vacationPeriod && vacationTypeSelectedVal) {

if (vacationTypeSelectedVal == "00804" || vacationTypeSelectedVal == "00805" ||
vacationTypeSelectedVal == "00810" || vacationTypeSelectedVal == "00820") {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/GetSickLeavesDistribution",
async: true,
data: {
"employeeNo": employeeNo,
"pSDate": vacationStartDate,
"pDays": vacationPeriod,
"systemCodeGroup": vacationTypeSelectedVal
},
contentType: "html",
cache: false,
success: function (result) {

$(".loader").fadeOut();

if (result == "") {

var selectedVacation = $("#RequestDetails_VacationRequestSettingId").find(":selected").text();

ReadFromResources("Ksu_SickLeavesDistributionMessage");
$(".SickLeavesDistributionMessage").html(resourceValue.replace("{0}", selectedVacation));
$("#RequestDetails_VacationRequestSettingId").val('');
$("#RequestDetails_VacationRequestSettingId").selectpicker('refresh');

$('#Modal_SickLeavesDistribution').addClass("md-show");

return false;

} else {
$('#DivSickleavesdistributionInfo').html(result);
$('#DivSickleavesdistribution').removeClass("md-show");

return true;
}
}
});
}
}
}


if it execute AddPeriodToDate() and return false, i want to stop not execute ShowSickLeavesDistributionInfo(null);










share|improve this question

























  • depending on your version of jquery the $.ajax call I believe will return a promise. you can then use Promise.all to resolve when all of those other promises have resolved.

    – Jhecht
    Nov 22 '18 at 20:22











  • thanks for your help, but i can't resolve it, would you please give me solution for my given code

    – Dev Net
    Nov 22 '18 at 20:38
















0















I need to wait for all Ajax request to be done before I execute the next although both async true
and I don't want to make async false because i want loader to be showen, here's my code



$('#RequestDetails_VacationPeriod').blur(function () {



        AddPeriodToDate();

ShowSickLeavesDistributionInfo(null);

});


function AddPeriodToDate() {



        var employeeNumber = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var periodValue = parseInt($("#RequestDetails_VacationPeriod").val());
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();
var totalLeavePeriodsUnderProcessing = $("#RequestDetails_TotalLeavePeriodsUnderProcessing").val();

if (vacationStartDate && periodValue && vacationTypeSelectedVal) {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/AddPeriodToDate",
async: true,
data: {
"employeeNumber": employeeNumber,
"vacationStartDate": vacationStartDate,
"periodValue": periodValue,
"totalLeavePeriodsUnderProcessing": totalLeavePeriodsUnderProcessing,
"decisionTypeNumber": vacationTypeSelectedVal
},
cache: true,
contentType: "application/json; charset=utf-8",
contentType: "json",
success: function (result) {

$(".loader").fadeOut();
$("#RequestDetails_VacationEndDate").val(result.VacationEndDate);

$("#RequestDetails_RemainingBalance").val(result.objVacationRequestDetail.RemainingBalance);

var remainingBalanceVal = parseInt($("#RequestDetails_RemainingBalance").val());

if (periodValue >= remainingBalanceVal) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_RemainingBalance').addClass("md-show");

return false;
} else {
$('#Modal_RemainingBalance').removeClass("md-show");

return true;
}

$("#RequestDetails_RemainigAnnualDays").val(result.objVacationRequestDetail.RemainigAnnualDays);
$("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing);
$("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing);

var remainingBalanceAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val();
var remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val();

if (parseInt(periodValue) > parseInt(remainingBalanceAfterDeductingLeavesPeriodUnderProcessing) ||
parseInt(periodValue) > parseInt(remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing)) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').addClass("md-show");

return false;

} else {
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').removeClass("md-show");

return true;
}
}
});
}
}


function ShowSickLeavesDistributionInfo(e) {



    var employeeNo = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var vacationPeriod = $("#RequestDetails_VacationPeriod").val();
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();

if ($(e) && $(e).attr("id") == "btn-Control") {

var sickLeavesDistributionRequiredMessage = "";

if (vacationTypeSelectedVal === "") {
ReadFromResources("Ksu_SickLeavesDistributionVacationsystemCodeGroupReuired");
sickLeavesDistributionRequiredMessage = resourceValue + " ,";
}

if (vacationStartDate === "") {

ReadFromResources("Ksu_SickLeavesDistributionVacationStartReuired");
sickLeavesDistributionRequiredMessage += resourceValue + " ,";
}

if (vacationPeriod === "") {
ReadFromResources("Ksu_SickLeavesDistributionvacationPeriodReuired");
sickLeavesDistributionRequiredMessage += resourceValue;
}

if (sickLeavesDistributionRequiredMessage) {

var lastChar = sickLeavesDistributionRequiredMessage.substr(sickLeavesDistributionRequiredMessage.length - 1);

if (lastChar === ",") {
sickLeavesDistributionRequiredMessage = sickLeavesDistributionRequiredMessage.slice(0, -1);
}

$(".SickLeavesDistributionParametersRequired").html(sickLeavesDistributionRequiredMessage);
$('#Modal_SickLeavesDistributionParametersRequired').addClass("md-show");

return false;
} else {
$('#Modal_SickLeavesDistributionParametersRequired').removeClass("md-show");

return true;
}
}

if (vacationStartDate && vacationPeriod && vacationTypeSelectedVal) {

if (vacationTypeSelectedVal == "00804" || vacationTypeSelectedVal == "00805" ||
vacationTypeSelectedVal == "00810" || vacationTypeSelectedVal == "00820") {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/GetSickLeavesDistribution",
async: true,
data: {
"employeeNo": employeeNo,
"pSDate": vacationStartDate,
"pDays": vacationPeriod,
"systemCodeGroup": vacationTypeSelectedVal
},
contentType: "html",
cache: false,
success: function (result) {

$(".loader").fadeOut();

if (result == "") {

var selectedVacation = $("#RequestDetails_VacationRequestSettingId").find(":selected").text();

ReadFromResources("Ksu_SickLeavesDistributionMessage");
$(".SickLeavesDistributionMessage").html(resourceValue.replace("{0}", selectedVacation));
$("#RequestDetails_VacationRequestSettingId").val('');
$("#RequestDetails_VacationRequestSettingId").selectpicker('refresh');

$('#Modal_SickLeavesDistribution').addClass("md-show");

return false;

} else {
$('#DivSickleavesdistributionInfo').html(result);
$('#DivSickleavesdistribution').removeClass("md-show");

return true;
}
}
});
}
}
}


if it execute AddPeriodToDate() and return false, i want to stop not execute ShowSickLeavesDistributionInfo(null);










share|improve this question

























  • depending on your version of jquery the $.ajax call I believe will return a promise. you can then use Promise.all to resolve when all of those other promises have resolved.

    – Jhecht
    Nov 22 '18 at 20:22











  • thanks for your help, but i can't resolve it, would you please give me solution for my given code

    – Dev Net
    Nov 22 '18 at 20:38














0












0








0








I need to wait for all Ajax request to be done before I execute the next although both async true
and I don't want to make async false because i want loader to be showen, here's my code



$('#RequestDetails_VacationPeriod').blur(function () {



        AddPeriodToDate();

ShowSickLeavesDistributionInfo(null);

});


function AddPeriodToDate() {



        var employeeNumber = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var periodValue = parseInt($("#RequestDetails_VacationPeriod").val());
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();
var totalLeavePeriodsUnderProcessing = $("#RequestDetails_TotalLeavePeriodsUnderProcessing").val();

if (vacationStartDate && periodValue && vacationTypeSelectedVal) {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/AddPeriodToDate",
async: true,
data: {
"employeeNumber": employeeNumber,
"vacationStartDate": vacationStartDate,
"periodValue": periodValue,
"totalLeavePeriodsUnderProcessing": totalLeavePeriodsUnderProcessing,
"decisionTypeNumber": vacationTypeSelectedVal
},
cache: true,
contentType: "application/json; charset=utf-8",
contentType: "json",
success: function (result) {

$(".loader").fadeOut();
$("#RequestDetails_VacationEndDate").val(result.VacationEndDate);

$("#RequestDetails_RemainingBalance").val(result.objVacationRequestDetail.RemainingBalance);

var remainingBalanceVal = parseInt($("#RequestDetails_RemainingBalance").val());

if (periodValue >= remainingBalanceVal) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_RemainingBalance').addClass("md-show");

return false;
} else {
$('#Modal_RemainingBalance').removeClass("md-show");

return true;
}

$("#RequestDetails_RemainigAnnualDays").val(result.objVacationRequestDetail.RemainigAnnualDays);
$("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing);
$("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing);

var remainingBalanceAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val();
var remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val();

if (parseInt(periodValue) > parseInt(remainingBalanceAfterDeductingLeavesPeriodUnderProcessing) ||
parseInt(periodValue) > parseInt(remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing)) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').addClass("md-show");

return false;

} else {
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').removeClass("md-show");

return true;
}
}
});
}
}


function ShowSickLeavesDistributionInfo(e) {



    var employeeNo = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var vacationPeriod = $("#RequestDetails_VacationPeriod").val();
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();

if ($(e) && $(e).attr("id") == "btn-Control") {

var sickLeavesDistributionRequiredMessage = "";

if (vacationTypeSelectedVal === "") {
ReadFromResources("Ksu_SickLeavesDistributionVacationsystemCodeGroupReuired");
sickLeavesDistributionRequiredMessage = resourceValue + " ,";
}

if (vacationStartDate === "") {

ReadFromResources("Ksu_SickLeavesDistributionVacationStartReuired");
sickLeavesDistributionRequiredMessage += resourceValue + " ,";
}

if (vacationPeriod === "") {
ReadFromResources("Ksu_SickLeavesDistributionvacationPeriodReuired");
sickLeavesDistributionRequiredMessage += resourceValue;
}

if (sickLeavesDistributionRequiredMessage) {

var lastChar = sickLeavesDistributionRequiredMessage.substr(sickLeavesDistributionRequiredMessage.length - 1);

if (lastChar === ",") {
sickLeavesDistributionRequiredMessage = sickLeavesDistributionRequiredMessage.slice(0, -1);
}

$(".SickLeavesDistributionParametersRequired").html(sickLeavesDistributionRequiredMessage);
$('#Modal_SickLeavesDistributionParametersRequired').addClass("md-show");

return false;
} else {
$('#Modal_SickLeavesDistributionParametersRequired').removeClass("md-show");

return true;
}
}

if (vacationStartDate && vacationPeriod && vacationTypeSelectedVal) {

if (vacationTypeSelectedVal == "00804" || vacationTypeSelectedVal == "00805" ||
vacationTypeSelectedVal == "00810" || vacationTypeSelectedVal == "00820") {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/GetSickLeavesDistribution",
async: true,
data: {
"employeeNo": employeeNo,
"pSDate": vacationStartDate,
"pDays": vacationPeriod,
"systemCodeGroup": vacationTypeSelectedVal
},
contentType: "html",
cache: false,
success: function (result) {

$(".loader").fadeOut();

if (result == "") {

var selectedVacation = $("#RequestDetails_VacationRequestSettingId").find(":selected").text();

ReadFromResources("Ksu_SickLeavesDistributionMessage");
$(".SickLeavesDistributionMessage").html(resourceValue.replace("{0}", selectedVacation));
$("#RequestDetails_VacationRequestSettingId").val('');
$("#RequestDetails_VacationRequestSettingId").selectpicker('refresh');

$('#Modal_SickLeavesDistribution').addClass("md-show");

return false;

} else {
$('#DivSickleavesdistributionInfo').html(result);
$('#DivSickleavesdistribution').removeClass("md-show");

return true;
}
}
});
}
}
}


if it execute AddPeriodToDate() and return false, i want to stop not execute ShowSickLeavesDistributionInfo(null);










share|improve this question
















I need to wait for all Ajax request to be done before I execute the next although both async true
and I don't want to make async false because i want loader to be showen, here's my code



$('#RequestDetails_VacationPeriod').blur(function () {



        AddPeriodToDate();

ShowSickLeavesDistributionInfo(null);

});


function AddPeriodToDate() {



        var employeeNumber = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var periodValue = parseInt($("#RequestDetails_VacationPeriod").val());
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();
var totalLeavePeriodsUnderProcessing = $("#RequestDetails_TotalLeavePeriodsUnderProcessing").val();

if (vacationStartDate && periodValue && vacationTypeSelectedVal) {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/AddPeriodToDate",
async: true,
data: {
"employeeNumber": employeeNumber,
"vacationStartDate": vacationStartDate,
"periodValue": periodValue,
"totalLeavePeriodsUnderProcessing": totalLeavePeriodsUnderProcessing,
"decisionTypeNumber": vacationTypeSelectedVal
},
cache: true,
contentType: "application/json; charset=utf-8",
contentType: "json",
success: function (result) {

$(".loader").fadeOut();
$("#RequestDetails_VacationEndDate").val(result.VacationEndDate);

$("#RequestDetails_RemainingBalance").val(result.objVacationRequestDetail.RemainingBalance);

var remainingBalanceVal = parseInt($("#RequestDetails_RemainingBalance").val());

if (periodValue >= remainingBalanceVal) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_RemainingBalance').addClass("md-show");

return false;
} else {
$('#Modal_RemainingBalance').removeClass("md-show");

return true;
}

$("#RequestDetails_RemainigAnnualDays").val(result.objVacationRequestDetail.RemainigAnnualDays);
$("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing);
$("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val(result.objVacationRequestDetail.RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing);

var remainingBalanceAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingBalanceAfterDeductingLeavesPeriodUnderProcessing").val();
var remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing = $("#RequestDetails_RemainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing").val();

if (parseInt(periodValue) > parseInt(remainingBalanceAfterDeductingLeavesPeriodUnderProcessing) ||
parseInt(periodValue) > parseInt(remainingAnnualDaysAfterDeductingLeavesPeriodUnderProcessing)) {

$("#RequestDetails_VacationPeriod").val("");
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').addClass("md-show");

return false;

} else {
$('#Modal_VacationBalanceWithUnderProccessingNotEnough').removeClass("md-show");

return true;
}
}
});
}
}


function ShowSickLeavesDistributionInfo(e) {



    var employeeNo = $("#RequestDetails_EmployeeNo").val();
var vacationStartDate = $("#VacationStartDate").val();
var vacationPeriod = $("#RequestDetails_VacationPeriod").val();
vacationTypeSelectedVal = $("#RequestDetails_VacationRequestSettingId").find(":selected").val();

if ($(e) && $(e).attr("id") == "btn-Control") {

var sickLeavesDistributionRequiredMessage = "";

if (vacationTypeSelectedVal === "") {
ReadFromResources("Ksu_SickLeavesDistributionVacationsystemCodeGroupReuired");
sickLeavesDistributionRequiredMessage = resourceValue + " ,";
}

if (vacationStartDate === "") {

ReadFromResources("Ksu_SickLeavesDistributionVacationStartReuired");
sickLeavesDistributionRequiredMessage += resourceValue + " ,";
}

if (vacationPeriod === "") {
ReadFromResources("Ksu_SickLeavesDistributionvacationPeriodReuired");
sickLeavesDistributionRequiredMessage += resourceValue;
}

if (sickLeavesDistributionRequiredMessage) {

var lastChar = sickLeavesDistributionRequiredMessage.substr(sickLeavesDistributionRequiredMessage.length - 1);

if (lastChar === ",") {
sickLeavesDistributionRequiredMessage = sickLeavesDistributionRequiredMessage.slice(0, -1);
}

$(".SickLeavesDistributionParametersRequired").html(sickLeavesDistributionRequiredMessage);
$('#Modal_SickLeavesDistributionParametersRequired').addClass("md-show");

return false;
} else {
$('#Modal_SickLeavesDistributionParametersRequired').removeClass("md-show");

return true;
}
}

if (vacationStartDate && vacationPeriod && vacationTypeSelectedVal) {

if (vacationTypeSelectedVal == "00804" || vacationTypeSelectedVal == "00805" ||
vacationTypeSelectedVal == "00810" || vacationTypeSelectedVal == "00820") {

$(".loader").fadeIn();

$.ajax({
type: "GET",
url: "/EServices/Leave/NewLeaveRequest/GetSickLeavesDistribution",
async: true,
data: {
"employeeNo": employeeNo,
"pSDate": vacationStartDate,
"pDays": vacationPeriod,
"systemCodeGroup": vacationTypeSelectedVal
},
contentType: "html",
cache: false,
success: function (result) {

$(".loader").fadeOut();

if (result == "") {

var selectedVacation = $("#RequestDetails_VacationRequestSettingId").find(":selected").text();

ReadFromResources("Ksu_SickLeavesDistributionMessage");
$(".SickLeavesDistributionMessage").html(resourceValue.replace("{0}", selectedVacation));
$("#RequestDetails_VacationRequestSettingId").val('');
$("#RequestDetails_VacationRequestSettingId").selectpicker('refresh');

$('#Modal_SickLeavesDistribution').addClass("md-show");

return false;

} else {
$('#DivSickleavesdistributionInfo').html(result);
$('#DivSickleavesdistribution').removeClass("md-show");

return true;
}
}
});
}
}
}


if it execute AddPeriodToDate() and return false, i want to stop not execute ShowSickLeavesDistributionInfo(null);







jquery model-view-controller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 20:23







Dev Net

















asked Nov 22 '18 at 20:19









Dev NetDev Net

33




33













  • depending on your version of jquery the $.ajax call I believe will return a promise. you can then use Promise.all to resolve when all of those other promises have resolved.

    – Jhecht
    Nov 22 '18 at 20:22











  • thanks for your help, but i can't resolve it, would you please give me solution for my given code

    – Dev Net
    Nov 22 '18 at 20:38



















  • depending on your version of jquery the $.ajax call I believe will return a promise. you can then use Promise.all to resolve when all of those other promises have resolved.

    – Jhecht
    Nov 22 '18 at 20:22











  • thanks for your help, but i can't resolve it, would you please give me solution for my given code

    – Dev Net
    Nov 22 '18 at 20:38

















depending on your version of jquery the $.ajax call I believe will return a promise. you can then use Promise.all to resolve when all of those other promises have resolved.

– Jhecht
Nov 22 '18 at 20:22





depending on your version of jquery the $.ajax call I believe will return a promise. you can then use Promise.all to resolve when all of those other promises have resolved.

– Jhecht
Nov 22 '18 at 20:22













thanks for your help, but i can't resolve it, would you please give me solution for my given code

– Dev Net
Nov 22 '18 at 20:38





thanks for your help, but i can't resolve it, would you please give me solution for my given code

– Dev Net
Nov 22 '18 at 20:38












1 Answer
1






active

oldest

votes


















0














Assuming you're using a recent enough version of jQuery (>= 1.5), the solution as mentioned in the jQuery documentation would be:



$.when( 
$.ajax( "/page1.php" ),
$.ajax( "/page2.php" )
).then( myFunc, myFailure );


In short, you can add up any number of ajax calls in the $.when clause, which will all be sent off asynchronously. Once all complete, the success or failure method is fired in the $.then clause.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437578%2fwait-for-async-ajax-requests-to-finish-although-both-async-true%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Assuming you're using a recent enough version of jQuery (>= 1.5), the solution as mentioned in the jQuery documentation would be:



    $.when( 
    $.ajax( "/page1.php" ),
    $.ajax( "/page2.php" )
    ).then( myFunc, myFailure );


    In short, you can add up any number of ajax calls in the $.when clause, which will all be sent off asynchronously. Once all complete, the success or failure method is fired in the $.then clause.






    share|improve this answer




























      0














      Assuming you're using a recent enough version of jQuery (>= 1.5), the solution as mentioned in the jQuery documentation would be:



      $.when( 
      $.ajax( "/page1.php" ),
      $.ajax( "/page2.php" )
      ).then( myFunc, myFailure );


      In short, you can add up any number of ajax calls in the $.when clause, which will all be sent off asynchronously. Once all complete, the success or failure method is fired in the $.then clause.






      share|improve this answer


























        0












        0








        0







        Assuming you're using a recent enough version of jQuery (>= 1.5), the solution as mentioned in the jQuery documentation would be:



        $.when( 
        $.ajax( "/page1.php" ),
        $.ajax( "/page2.php" )
        ).then( myFunc, myFailure );


        In short, you can add up any number of ajax calls in the $.when clause, which will all be sent off asynchronously. Once all complete, the success or failure method is fired in the $.then clause.






        share|improve this answer













        Assuming you're using a recent enough version of jQuery (>= 1.5), the solution as mentioned in the jQuery documentation would be:



        $.when( 
        $.ajax( "/page1.php" ),
        $.ajax( "/page2.php" )
        ).then( myFunc, myFailure );


        In short, you can add up any number of ajax calls in the $.when clause, which will all be sent off asynchronously. Once all complete, the success or failure method is fired in the $.then clause.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 20:33









        Eric VautierEric Vautier

        943




        943
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437578%2fwait-for-async-ajax-requests-to-finish-although-both-async-true%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]