var characterName = document.getElementById("pilotName").value;
var characterID = 0;
var charSecStatus = 0;
var corpName = " ";
var allianceName = " ";
//callback
makeRequest('https://api.eveonline.com/eve/CharacterID.xml.aspx?names=' + characterName, function() {
if (xmlhttp.status == OK_RESPONSE) {
//read character info
characterID = xmlhttp.responseXML.getElementsByTagName("row")[0].getAttribute("characterID");
makeRequest('https://api.eveonline.com/eve/CharacterInfo.xml.aspx?characterID=' + characterID, function() {
if (xmlhttp.status == OK_RESPONSE) {
//read character info
characterID = xmlhttp.responseXML.getElementsByTagName("characterID")[0].innerHTML;
charSecStatus = xmlhttp.responseXML.getElementsByTagName("securityStatus")[0].innerHTML;
corpName = xmlhttp.responseXML.getElementsByTagName("corporation")[0].innerHTML;
allianceName = (xmlhttp.responseXML.getElementsByTagName("alliance")[0] || {
innerHTML: ""
}).innerHTML;
}
});
}
});
(部分代码如图所示,不要加括号) 我正在尝试检查“alliance”变量是否为空,因为某些“公司”不在“联盟”中,如果尝试显示一个空变量,这将是网站的关键错误。那么,在从XML树中检索并设置allianceName后,是否有一种方法来检查是否为空并将其设置为“无联盟”?谢谢。