javascript - Waiting for AJAX request response -
i have following function stores data in abc.printreport.reportdata. grab data ajax requests. want print data in new window open @ end of getkeydata function.
however, time window opens, ajax requests have not returned data, errors undefined properties. solution this?
getkeydata: function () { (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'); },
even though there variable number of requests going on, can keep track of them , open window in success method when last request completes.
getkeydata: function () { var total = abc.printreport.keylist.length; var loaded = 0; (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]; loaded++; if (loaded == total) { window.open(location.pathname + 'resources/printreport.html'); } } }); })(k); } },
Comments
Post a Comment