【发布时间】:2016-05-03 12:40:55
【问题描述】:
我需要做几次阅读 HTTP,我需要等待响应。但是 HTTP 是异步的。那我也不知道怎么办了。
我的代码是:
var clientelee = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
Ti.API.info("******* Recibido: " + this.responseText);
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug("****** ERROR *********"+e.error);
},
onreadystatechange: function(e){
Ti.API.info("******* STATUS *********"+e.readyState);
},
timeout : 3000 // in milliseconds
});
function LeeDatos(){
url = "http://www.hola.com/read/"+leoSerie;
// Prepare the connection.
clientelee.open("GET", url);
// Send the request.
clientelee.send();
}
for (i=0;i<NRegistros;i++){
TablaSerieTermostatos[i]=rows.field(0);
leoSerie=rows.field(0);
LeeDatos();
......
}
有什么建议吗??谢谢
【问题讨论】:
-
你在使用 NodeJS 吗?如果是这样,我相信你需要一个像async 这样的库,等待几个调用完成,然后启动回调
标签: javascript http appcelerator appcelerator-titanium