0

請讓我陷入一個小問題使用PhoneGap項目的js文件上的getElementsByTagName命令。我正在使用一個完美的asp.net web服務,但是我沒有得到web服務返回給我的結果,那就是<IngresarRegistroMovilResult>標籤中的string如何從特定的asp.net web服務getelementbytagname

這是我的功能,其接收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; 

    } 
}; 

這是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> 

這是對應於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 undefinedtheXML.getElementsByTagName('string')[0];但我得到:undefinedtheXML.getElementsByTagName('string')[0].nodeValue;但我得到:Uncaught TypeError: Cannot read property 'nodeValue' of undefined

請大家的支持對我非常有價值。

謝謝。

回答

0

標記名IngresarRegistroMovilResultstring您可以通過theXML.getElementsByTagName('IngresarRegistroMovilResult')[0].textContent存取權限(如果我再沒錯字)

+0

謝謝,deamentiaemundi,爲您的答覆。我收到錯誤消息'Uncaught TypeError:無法在main.js的第39行讀取'undefined'屬性'textContent'。錯誤消息顯示「未定義」。它說'theXML.getElementsByTagName('IngresarRegistroMovilResult')[0]'是未定義的。爲什麼? – Gabms

+0

Mmh ...不,mime類型沒問題,但仍可能無法返回DOM。嘗試通過在頂部添加強制DOM:'var parser = new DOMParser(); var theXML = parser.parseFromString(xmlhttp.responseXML,「text/xml」)。documentElement;'如果這不起作用。 .well,我不是那個放棄*那個*的人;-) – deamentiaemundi

+0

好吧,@deamentiaemundi我發現了一些好奇的東西:消費Web服務的結果具有來自Web服務的返回變量的值。換句話說,'theXML.innerHTML'包含'C ---- O',即'IngresarRegistroMovilResult'的字符串值,flat,沒有標籤。然後,我得到的錯誤是試圖通過標記名獲取返回值。我將結束這個問題。謝謝@deamentiaemundi的合作。 – Gabms

0

使用Web服務的結果具有從Web服務返回變量的值。換句話說,XML.innerHTML包含C ---- O,即IngresarRegistroMovilResult的字符串值,不帶標籤。然後,我得到的錯誤是試圖通過標記名獲取返回值。