Getting XML nodevalue with Javascript

依然范特西╮ 提交于 2020-01-01 05:46:09

问题


I am trying to figure out how to get a node's value in Javascript. I've read a few tutorials but the examples they use are all much more complex than what I'm doing..

Here's my Javascript

        if(xmlhttpp.readyState==4 && xmlhttpp.status==200){
            document.getElementById("ajax_status").innerHTML=xmlhttpp.responseXML.getElementsByTagName('status').nodeValue;
        }

And the XML is..

<?xml version='1.0' encoding='UTF-8'?>
<resp><fname>Kyla</fname>
<lname>Bonds</lname>
<addr>6916 S Elizabeth Street</addr>
<city>Chicago</city>
<street>IL</street>
<zip>60636</zip>
<phone></phone>
<email>Kbonds20@gmail.com</email>
<status>Found user</status></resp>

How can I get "Found User" from this?


回答1:


Try

xmlhttpp.responseXML.getElementsByTagName('status')[0].firstChild.nodeValue


来源:https://stackoverflow.com/questions/16249605/getting-xml-nodevalue-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!