I have a function that will return an AJAX response and use it on another function. Here is my code:
function updateLoanApproval(answer){
var password = document.getElementById("password").value;
var usid;
getExistingId(function(success){
if (success === 0){
var usid = "No ID Available";
} else {
var usid = success; //To get the returning value
}
});
alert(usid);
And here is the code for getExistingId()
function getExistingId(){
var url = "../../library/functions.php?action=getId";
var uid;
http.onreadystatechange = function(){
if (http.status == 200 && (http.readyState === 4)){
uid = http.responseText;
if (uid == "No ID"){
callback(0);
} else {
callback(id);
}
}
}
http.open("GET",url,true);
http.send();
}
As I test the code, I don't have a problem with a query or PHP code so I will not include it here, but why is usid
always return undefined?