I am encountering an issue while calling sub functions connected to if statements within my main function. Even though the sub functions are supposed to return true or false, the expected alerts are not appearing.
if (functionAAA()){ alert("111111111"); if (functionBBB()){ alert("2222222"); if (functionCCC()){ alert("333333333333"); } } }
The functions functionAAA, functionBBB, and functionCCC are expected to return true, triggering alerts accordingly. However, this behavior is not happening as anticipated. What could be going wrong in my implementation?
I suspect that the issue lies within the function side itself. The definition of functionAAA is provided below:
function functionAAA(){
var indexId = 1;
var dataItem = datasourceAppList.at(indexId);
var deviceKey = localStorage.getItem('LsDeviceKey');
var baseUrl = localStorage.getItem('LsBaseUrl');
var errorMessageInfoText;
var status;
$.ajax({
url: baseUrl + '/test/cloud/FE/1.0/test.php',
data: {
PAR1: dataItem.par1,
PAR2: dataItem.par2,
PAR3: deviceKey,
PAR4: dataItem.par3,
PAR5: "5664456"
},
type: 'GET',
crossDomain: true,
dataType: 'jsonp',
error: function () {
showErrorDialog("Key Validation Failure");
}
}).done(function (data) {
$.each(data, function (k, v) {
// alert("k " + k + " v " + v);
if (k == 'STATUS') {
status = v;
} else if (k == 'ERROR_MESSAGE') {
errorMessageInfoText = v;
}
});
if (status == 'TRUE') {
alert("ok");
return true;
} else {
return false;
};
});
}
The other functions mentioned directly return true without any issues.
Additionally, it's worth noting that I do receive the "ok" alert within the function when necessary.