我正在使用Appcelerator Titanium,下面的代码在iPhone上工作正常,但在Android上没有,我无法找到原因。有人可以帮忙吗?
失败并出现以下错误:
TypeError:无法从null
读取属性“DocumentElement”BEGIN CODE
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
var xmlDoc = Ti.XML.parseString(this.responseText).documentElement;
var xlinestatus = xmlDoc.getElementsByTagName('LineStatus');
for (i = 0; i < xlinestatus.length; i++) {
var theItem = xlinestatus.item(i);
var newname = theItem.getElementsByTagName("Line").item(0).getAttribute("Name");
var desc = theItem.getElementsByTagName("Status").item(0).getAttribute("Description");
var active = theItem.getElementsByTagName("Status").item(0).getAttribute("IsActive");
Ti.API.info(" Line: " + newname + " Status: " + desc + ", Active: " + active);
}
};
// open the client
xhr.open('GET', 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus');
// send the data
xhr.send({});
END CODE
答案 0 :(得分:0)
这就是我所做的并且有效
请更改第Ti.XML.parseString(this.responseText).documentElement;
行
到
this.responseXML.documentElement
它应该有效。这是它的输出。我没有在OS X上测试它,但它应该可以工作。
[INFO] [157,5791] Line: Bakerloo Status: Service Closed, Active: true
[INFO] [8,5799] Line: Central Status: Service Closed, Active: true
[INFO] [27,5826] Line: Circle Status: Service Closed, Active: true
[INFO] [7,5833] Line: District Status: Service Closed, Active: true
[INFO] [16,5849] Line: Hammersmith and City Status: Service Closed, Active: true
[INFO] [11,5860] Line: Jubilee Status: Service Closed, Active: true
[INFO] [12,5872] Line: Metropolitan Status: Service Closed, Active: true
[INFO] [12,5884] Line: Northern Status: Service Closed, Active: true
[INFO] [14,5898] Line: Piccadilly Status: Service Closed, Active: true
[INFO] [14,5912] Line: Victoria Status: Service Closed, Active: true
[INFO] [14,5926] Line: Waterloo and City Status: Service Closed, Active: true