由网友(丨瞬间丿灬迷茫)分享简介:我有一个函数来验证code与AJAX(PHP)。然而,当我尝试运行它,它会返回未定义时,它应该返回真或假。I have a function to validate a code with AJAX(PHP). However, when I try to run it, it returns undefined w...
我有一个函数来验证code与AJAX(PHP)。然而,当我尝试运行它,它会返回未定义
时,它应该返回真
或假
。
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 verifyViite(viite) {
$.get('dataminer.php?question=validateViite&q='+viite, function(data) {
jQuery.globalEval(data);
if(valid == 1) {
return true;
}
else {
return false;
}
});
}
在数据
是有效期= 1;
或有效期= 0;
推荐答案
您不能在回调返回值返回由于AJAX请求是异步的。
You can't return the Callback return value due to the AJAX request being asynchronous.
执行任何code调用 verifyViite
回调本身中,而不是返回true或false。
Execute whatever code calling verifyViite
inside the callback itself, instead of returning true or false.
Alternativly,你可以有synchronous AJAX请求。
Alternativly, you can have synchronous AJAX request.
相关推荐
最新文章