简体   繁体   中英

JavaScript - IE 9 XML textContent

The next code works well under Firefox, but IE 9 gives udnefiend as result:

var url = "http://www.w3schools.com/xml/note.xml";

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function(event){ processRequest(event,xmlhttp); };
xmlhttp.send();

function processRequest(event,xmlhttp) {
    if(xmlhttp.readyState != 4) return;
    if(xmlhttp.status != 200) return;
    var responseXML = xmlhttp.responseXML;
    alert(responseXML.getElementsByTagName("note")[0].getElementsByTagName("to")[0].textContent);
}

How can I get the textContent of an XML element in IE9?

To access the value of any node from an XML DOM object, use the property

dom_node.nodeValue;

textContent is not a W3C standard recommendation. Request you to use the standard properties which are cross-browser compatible.

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