我在 Titanium Appcelerator 中使用以下代码连接远程主机:
var connect_remote = function(url)
{
/*
* make sure that the Device is connected before initiate process as we don't want to force
* the user to open remote stream just for sake of new entries
*/
//alert("In Func" + is_connected());
var d_data = null;
if(is_connected())
{
var c = Titanium.Network.createHTTPClient();
var data = null;
c.setTimeout(10000);
c.onload = function()
{
if (c.status == 200 )
{
data = this.responseData;
Titanium.App.Properties.setString('returnData',data);
}
};
c.error = function(e)
{
alert("Error = "+e.error);
}
c.open('GET',url);
c.send();
}
}
我想返回应该保留响应值的数据变量的值,以便我可以使用,但它总是返回 null 或未定义。如何从中返回值数据?