开发者

Parsing prototype AJAX.response XML in IE

I have an xml webservice which I'm fetching using PrototypeJS. The xml has the correct content type and is well-formed, and looks like this:

<GetTokenResp开发者_JS百科onse xmlns="http://tempuri.org/">
    <GetTokenResult>F655100D64F098F0AC33AFF414A4A0D5</GetTokenResult>
</GetTokenResponse>

The AJAX request is completing successfully, and I can access the GetTokenResult node in both IE and FF but can only get the text content of the node in FF. My code is below:

node = transport.responseXML.documentElement.getElementsByTagName('GetTokenResult')[0];
rawToken = (document.all) ? node.innerText : node.textContent;

I've tried innerText and innerHTML, as well as children[0] and a few other chance guesses but IE returns 'undefined' when I access rawToken.

Anyone able to lend a hand? Thanks, Adam


Try accessing the node value as:

rawToken = node.firstChild.data;

This should work across all modern browsers, as well as IE.


To get the text content, use firstChild.nodeValue


node = transport.responseXML - this is correct.

You end up with "node" as your XML in string format. Strip the rest. You need to turn the string into an XML document before you can manipulate it directly.

See: Convert String to XML Document in JavaScript

or see: http://www.discussweb.com/html-css-javascript-coding-techniques/3308-convert-ordinary-string-into-xml.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜