简体   繁体   中英

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. 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.

This is my function that receives the web service return:

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:

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:

<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; but I get: Uncaught TypeError: Cannot read property 'firstChild' of undefined . theXML.getElementsByTagName('string')[0]; but I get: undefined . theXML.getElementsByTagName('string')[0].nodeValue; but I get: 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. In other words, theXML.innerHTML contains C----O, that is the string value of IngresarRegistroMovilResult, flat, without tags. The error I was getting, then, is for trying to get the return value through a tagname.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM