I have a function to validate a code with AJAX(PHP). However, when I try to run it, it returns undefined when it should return true or false.
function:
function verifyViite(viite) {
$.get('dataminer.php?question=validateViite&q='+viite, function(data) {
jQuery.globalEval(data);
if(valid == 1) {
return true;
}
else {
return false;
}
});
}
The data is either valid = 1; or valid = 0;
You can’t return the Callback return value due to the AJAX request being asynchronous.
Execute whatever code calling
verifyViiteinside the callback itself, instead of returning true or false.Alternativly, you can have synchronous AJAX request.