[英]How to getelementbytagname from specific asp.net web service
Please, I'm stuck in a little problem using getElementsByTagName command on a js file with a PhoneGap project. 请,我在一个带有PhoneGap项目的js文件上使用getElementsByTagName命令遇到了一个小问题。 I'm consuming a asp.net web service that works perfectly, but I failed to get the result that the web service is returning me, and that is
string
from <IngresarRegistroMovilResult>
tag. 我正在使用可正常运行的asp.net Web服务,但无法获得Web服务返回我的结果,该结果是
<IngresarRegistroMovilResult>
标记中的string
。
This is my function that receives the web service return: 这是我接收Web服务返回的函数:
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;
}
};
This is the specification of the web service: 这是Web服务的规范:
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>
This is the fragment corresponding to IngresarRegistroMovil method, from the wsdl: 这是与wsdl中的IngresarRegistroMovil方法相对应的片段:
<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>
I've tried theXML.getElementsByTagName('string')[0].firstChild.nodeValue;
我已经尝试过
theXML.getElementsByTagName('string')[0].firstChild.nodeValue;
but I get: Uncaught TypeError: Cannot read property 'firstChild' of undefined
. 但我得到:
Uncaught TypeError: Cannot read property 'firstChild' of undefined
。 theXML.getElementsByTagName('string')[0];
but I get: undefined
. 但我得到:
undefined
。 theXML.getElementsByTagName('string')[0].nodeValue;
but I get: Uncaught TypeError: Cannot read property 'nodeValue' of undefined
. 但是我得到了:
Uncaught TypeError: Cannot read property 'nodeValue' of undefined
。
Please, your great support will be extremely valuable to me. 拜托,您的大力支持对我来说将是非常宝贵的。
Thanks. 谢谢。
标记名是IngresarRegistroMovilResult
而不是string
,您可以通过theXML.getElementsByTagName('IngresarRegistroMovilResult')[0].textContent
(如果我没有输入错字)
The result of consuming the web service has the value of the return variable from the web service. 使用Web服务的结果具有Web服务的返回变量的值。 In other words, theXML.innerHTML contains C----O, that is the string value of IngresarRegistroMovilResult, flat, without tags.
换句话说,XML.innerHTML包含C ---- O,即IngresarRegistroMovilResult的字符串值,平面,不带标签。 The error I was getting, then, is for trying to get the return value through a tagname.
那么,我得到的错误是试图通过标记名获取返回值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.