【发布时间】:2014-04-24 08:45:51
【问题描述】:
我有以下函数将一些数据存储在ABC.PrintReport.reportData 中。
我使用 AJAX 请求获取数据。然后我想在getKeyData 函数末尾打开的新窗口中打印数据。
但是,当窗口打开时,AJAX 请求还没有返回数据,所以我收到有关未定义属性的错误。有什么办法解决这个问题?
getKeyData: function () {
for (var key in ABC.PrintReport.keyList) {
k = ABC.PrintReport.keyList[key].Report_Key;
ABC.PrintReport.reportData[k] = null;
(function(index) {
Ext.Ajax.request({
url: ABC.Core.servicePath + '/task/' + ABC.PrintReport.processInstanceID + '/report/' + ABC.PrintReport.keyList[key].Report_Key + '?portalID=' + ABC.Core.portalID,
success: function (response) {
ABC.PrintReport.reportData[index] = Ext.JSON.decode(response.responseText)[0];
}
});
})(k);
}
window.open(location.pathname + 'resources/printreport.html');
},
【问题讨论】:
-
为什么不在你的 Ajax 请求的
success函数中打开它? -
在你的成功函数中打开窗口
-
有多个ajax请求。可以是 3 到 6 之间的任何值。请求处于 for 循环中。
标签: javascript ajax