【发布时间】:2009-05-05 11:19:04
【问题描述】:
我正在尝试在函数中使用 $.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;
}
【问题讨论】:
标签: jquery post variables global