SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Jun 7, 2007, 02:04 #1
- Join Date
- Oct 2005
- Posts
- 405
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
JavaScript Wont Output XML Content
I keep getting this error when i run this script.
Error reading the response: ReferenceError - Can't find variable: childNodes
Thanks
http://www.callsabroad.gb.com/
Code:function handleServerResponse() { var xmlResponse = xmlHttp.responseXML; //catching potential errors with IE and Opera if(!xmlResponse || !xmlResponse.documentElement) throw("Invalid XML Structure:\n" + xmlHttp.responseText); //catching potential errors with Firefox var rootNodeName = xmlResponse.documentElement.nodeName; if(rootNodeName == "parsererror") throw("Invalid XML Structure:\n" + xmlHttp.responseText); //obtain the XML documents element xmlRoot = xmlResponse.documentElement; //testing that we received the XML document we expect if(rootNodeName != "response" || !xmlRoot.firstChild) throw("Invalid XML Structure:\n" + xmlHttp.responseText); responseText = getNodeValue(xmlRoot.lastChild); //display the user message myDiv = document.getElementById("myDivElement"); myDiv.innerHTML = responseText; } function getNodeValue(node) { var nodeValue = []; var i = end = 0; var child = null; if (node.childNodes) { end = childNodes.length; for (i; i < end; i++) { child = node.childNodes[i]; if (child.nodeName === '#text') { nodeValue.push(child.nodeValue); } } } else if (node.nodeValue) { nodeValue.push(node.nodeValue); } return nodeValue.join(''); }
-
Jun 7, 2007, 02:25 #2
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
So you didn't test getNodeValue() independently?
Code:end = childNodes.length;
Code:end = node.childNodes.length;
We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
-
Jun 7, 2007, 03:46 #3
- Join Date
- Oct 2005
- Posts
- 405
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks that sorted it.
Bookmarks