Tidesdk 打开外部网页时出现问题
我正在尝试使用以下代码在子窗口中打开外部网页Tidesdk 打开外部网页时出现问题,tidesdk,Tidesdk,我正在尝试使用以下代码在子窗口中打开外部网页 var secondwindow = Ti.UI.createWindow("http://www.google.com"); 这个以前可以正常工作,但突然它停止了工作,我也试着打开它 window.location.assign("http://www.google.com"); 但这也不行。应用程序控制台输出为 URL的[Ti.Network.Analytics][Error]失败:无法连接到服务器 有人能告诉我这里发生了什么吗?据我所知(刚
var secondwindow = Ti.UI.createWindow("http://www.google.com");
这个以前可以正常工作,但突然它停止了工作,我也试着打开它
window.location.assign("http://www.google.com");
但这也不行。应用程序控制台输出为
URL的[Ti.Network.Analytics][Error]失败:无法连接到服务器
有人能告诉我这里发生了什么吗?据我所知(刚刚开始学习SDK),你不能这样做。您可以通过编写html文件在应用程序包中定义自己的窗口,使用Ti.UI对象打开窗口,并使用Ti.Network命名空间的HTTPCLient获取外部html内容。这样,您就可以加载所需的HTML内容或其他类似JSON的内容,并将其植入到您的窗口HTMLDOM中
例如:
首先,您将使用自己的html文件创建一个新窗口:
Ti.UI.createWindow("app://special-window.html")
在该文件中,您将执行一些Javascript以获取一些外部资源,如HTML:
//Request URL
var url = 'http://mywebsite.com/api/users/';
//Create the HTTP Client
var client = Ti.Network.createHTTPClient({
onload: function(e) {
//request complete do something with data
//assuming that we are not working with XML
Ti.API.INFO('Response received '+this.responseText);
// DO SOMETHING WITH THE this.responseText HERE (like adding it to your DOM)
},
onerror: function(e) {
//error received, do something
}
});
//Specify request type and open
client.open('GET',url);
//Send request
client.send();
代码取自文档。(如我所说,我刚刚开始使用SDK)
希望,我能帮点忙:)