# AJAX and childNodes\[\]

**URL:** <https://forum.kirupa.com/t/ajax-and-childnodes/176464>\
**Category:** web dev\
**Created:** [January 24, 2006, 11:51am UTC](https://forum.kirupa.com/t/ajax-and-childnodes/176464 "2006-01-24T11:51:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sammo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sammo/32/779_2.png) [@Sammo](https://forum.kirupa.com/u/Sammo)\
**Post date:** [January 24, 2006, 11:51am UTC](https://forum.kirupa.com/t/ajax-and-childnodes/176464/1 "2006-01-24T11:51:27Z")

</div>

Hey, I’ve been trying to get the grips with some basic ajax, but i’m having some problems. I can’t seem to get childNodes to ever work.

```javascript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" language="javascript">
			function makeRequest(url, e) {
				elem = document.getElementById(e);
				elem.innerHTML = "Loading...";
				if (window.XMLHttpRequest) {
					http_request = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				if (!http_request) {
					alert('Giving up :( Cannot create an XMLHTTP instance');
					return false;
				}
				http_request.onreadystatechange = outContent;
				http_request.open('GET', url, true);
				http_request.send(null);
			}
			function outContent() {
				if (http_request.readyState == 4) {
					if (http_request.status == 200) {
						var xmldoc = http_request.responseXML;
						var root_node = xmldoc.getElementsByTagName('root');
						elem.innerHTML = root_node[0].childNodes[0].firstChild.text;
					} else {
						elem.innerHTML = 'There was a problem with the request.';
					}
				}
			}
        </script>
    </head>
    <body>
        <span style="cursor: pointer; text-decoration: underline" onclick="makeRequest('test.xml', 'load')">
                Make a request
        </span>
		<div id="load"></div>
    </body>
</html>

```

This is the code I’m using, and it’s called this file:

```xml
<?xml version="1.0" ?>
<root>
    <text>I'm a test.</text>
</root>

```

If I run the hasChildNodes() function it returns true, and I can get the tagName variables of the root tag, but whenever I throw a childNodes into it all I see is “Loading…” with no output of the data.
