Titanium在url中打开远程数据

时间:2016-06-06 04:52:15

标签: api titanium-alloy appcelerator-titanium titanium-studio

我将远程数据解析到我的应用程序并通过参数使用它。其中一种数据类型是我想要在网址中打开的网址。我有一个想法,我必须用openURL函数打开它,但我似乎无法让它工作。有人有一个工作的例子吗?

1 个答案:

答案 0 :(得分:0)

您必须使用内置HttpClient

var url = "http://www.you_remote_url.com";

var client = Ti.Network.createHTTPClient({
   // function called when the response data is available
   onload : function(e) {
     Ti.API.info("Received text: " + this.responseText);
     alert('success');
   },
   // function called when an error occurs, including a timeout
   onerror : function(e) {
     Ti.API.debug(e.error);
     alert('error');
   },
   timeout : 5000  // in milliseconds
 });

 // Prepare the connection.
 client.open("GET", url);
 // Send the request.
 client.send();