troubleshooting Question

ResponseXML is always null in Javascript from XML echo at PHP

Avatar of namsu55
namsu55Flag for United Kingdom of Great Britain and Northern Ireland asked on
2 Comments1 Solution328 ViewsLast Modified:
I am trying to capture a response from XML using AJAX into JavaScript. The XML is full functioning as I have tried a test script on a file on its own and it works fine. However when accessing the XML data using JavaScript DOM I always get NULL as tested using alert. I have verified that JavaScript can pick up the right node name, however not get the value, even if i try a simple "Hello".

Here is my XML in PHP:
   echo"<?xml version='1.0' encoding=\"utf-8\"?>";
   echo "<data>";
   echo "<pause>" .$_SESSION['prog'].  "</pause>";
   echo "</data>";
I have set the content type to XML at the top of the document.

My AJAX JavaScript Code:

 function ajaxGetPHP()


                if(http1.readyState == 4 && http1.status == 200) {

                    //document.getElementById("r").innerHTML = http1.responseText;

                    var xmlDoc = http1.responseXML.documentElement;
                    document.getElementById("r").innerHTML = xmlDoc.getElementsByTagName("pause")[0].nodeName;
                    load = xmlDoc.getElementsByTagName("pause")[0].nodeValue;

                } else {
                    document.getElementById("s").innerHTML = http1.readyState;



I have tried several techniques and have been following various tutorials especially at W3Schools. Any help would be appreciated on this.
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros