我正在使用ajax并成功获得响应。我无法理解,为什么if-else条件未按预期返回布尔值。不知道我是否在正确的地方使用退货。需要帮忙。
validateEverPresentRowWidgetValue: function (datafield, value, rowValues) {
if ((!value)) {
$.alert({
content: 'Please select Date!',
btnClass: 'btn-warning',
boxWidth: '30%',
title: 'Missed something!',
type: 'orange',
typeAnimated: true,
useBootstrap: false
});
return false; //Works fine
} else if (value) {
$.ajax({
url: 'checkForLeave.php',
dataType: 'json',
method: 'post',
data: {date: value},
success: function (response) {
if (response.length > 0) {
$.confirm({
title: 'Confirm!',
content: 'This date is NOT allowed! <br> Reason:' + response[0].comments,
boxWidth: '30%',
typeAnimated: true,
useBootstrap: false,
btnClass: 'btn-warning',
type: 'orange',
buttons: {
confirm: function () {
return true; //Problem in return
},
cancel: function () {
return false; //Problem in return
}
}
});
} else {
return true;
}
},
error: function (response) {
return false;
}
});
}
}