【发布时间】:2015-11-20 01:03:17
【问题描述】:
拜托,我在一个带有 PhoneGap 项目的 js 文件上使用 getElementsByTagName 命令遇到了一个小问题。我正在使用一个运行良好的 asp.net 网络服务,但我没有得到网络服务返回我的结果,即来自<IngresarRegistroMovilResult> 标记的string。
这是我接收网络服务返回的函数:
function processResult() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var theXML = xmlhttp.responseXML.documentElement;
var resultadoWebService = theXML.getElementsByTagName('string')[0].firstChild.nodeValue;
var output = "Resultado: ";
output += resultadoWebService;
console.log("Pasamos por processResult, con var output:"+output);
document.getElementById("resultadows").innerHTML = output;
}
};
这是网络服务的规范:
POST /servicio.asmx HTTP/1.1
Host: dondeestamifamilia.masterdevelopment.co
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<IngresarRegistroMovil xmlns="http://dondeestamifamilia.masterdevelopment.co/">
<hashString>string</hashString>
</IngresarRegistroMovil>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<IngresarRegistroMovilResponse xmlns="http://dondeestamifamilia.masterdevelopment.co/">
<IngresarRegistroMovilResult>string</IngresarRegistroMovilResult>
</IngresarRegistroMovilResponse>
</soap12:Body>
</soap12:Envelope>
这是IngresarRegistroMovil方法对应的片段,来自wsdl:
<s:element name="IngresarRegistroMovil">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="hashString" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="IngresarRegistroMovilResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="IngresarRegistroMovilResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
我试过theXML.getElementsByTagName('string')[0].firstChild.nodeValue;
但我得到:Uncaught TypeError: Cannot read property 'firstChild' of undefined。 theXML.getElementsByTagName('string')[0]; 但我得到:undefined。 theXML.getElementsByTagName('string')[0].nodeValue; 但我得到:Uncaught TypeError: Cannot read property 'nodeValue' of undefined。
拜托,您的大力支持对我来说非常宝贵。
谢谢。
【问题讨论】:
标签: javascript asp.net web-services cordova getelementsbytagname