如何在 get 本身之外访问从 xhrGet 返回的数据? Firebug 显示“json”对象有一个名为 results 的数组,该数组存储响应中的 json 对象,但当我尝试访问它时它为 null。那么:如何访问最后一个代码行接收到的数据?
var json = dojo.xhrGet({
url :'/disease_web/graphMlDownload/getEdgeInformation/', handleAs:"json",content : { edgeid : edgeId, graphname:this._canvas.path},
load:function(response){
return response;
}
});
console.log(json.ioArgs);
console.log(json.results);
默认情况下,dojo.xhrGet 是异步调用的,因此 console.log(json.results) 为 null,因为它在 dojo.xhrGet 之后运行,但在服务器发出响应之前运行。
var xhrGet = dojo.xhrGet({
url: "/some_rul",
handleAs: "json",
handle: function(response) {
console.info(2,'response',response);
console.info(3,'xhrGet.results[0]',xhrGet.results[0]);
}
});
console.info(1,xhrGet.hasOwnProperty('results'));
结果是:
1 false
2 响应 - ['来自服务器的一些数据']
3 xhrGet.results[0] - 与通过 xhrGet 访问的“响应”中的数据相同
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)