The else block gets executed always before validating the if condition. The proceedToNextValidation() executed before the Validation(clusterId) gets fully completed its execution. How to wait for the function Validation(clusterId) to be executed fully and then based on its result evaluate the if-else block.
function validateUpgradateStatus()
{
var target = $("#selectcluster").data("ejDropDownList");
var clusterId = target.model.itemValue;
var isValidated = Validation(clusterId);
if(isValidated )
Error("error msg");
else
proceedToNextValidation();
}
function Validation(id) {
$.ajax({
type: "POST",
url: '@Url.Action("Method", "Controller")',
data: {
clusterId: id,
},
success: function (response) {
if (response.isSdkUpgrading) {
return true;
}
else {
return false;
}
}
});
}