我试图在函数中使用 $.post,获取结果,然后根据 $.post 回调的结果返回函数 true 或 false。但是,回调似乎发生在父函数的返回事件之后。
这是 ret 变量始终未定义的当前代码,但如果我在 $.post 回调中警告()它,它会返回正确的结果;
function elementExists(key, type, path, appid, pid){
var ret;
$.post('?do=elExists', {key: key, type: type, path: path, appid: appid, pid: pid},function(data){
ret = data;
});
alert(ret);
return ret;
}