logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: XMLHttpRequest.responseXML isn't working for me.
Author
larryl



Joined: 28 Nov 2012
Posts: 3
Location: USA, Portland

PostPosted: Wed 28 Nov '12 23:00    Post subject: XMLHttpRequest.responseXML isn't working for me. Reply with quote

Hello Folks:

I'm running Apache 2.2.15 on Solaris. This system is for, among other things, developing code that I'll move to my web site, on a hosting service.

Should I upgrade Apache? I intend to upgrade eventually, but I have other priorities right now.

I can't get XMLHttpRequest.responseXML to work.

The code works on my hosted web site, but fails on my system. So I'm guessing there is something wrong with my Apache setup.

This seems to work:
Code:

     xmlDoc=xmlhttp.responseXML;


And this seems to work:

Code:

      xmlhttp.open("GET","note.xml",false);
      xmlhttp.send();


Because this seems to work:

Code:

      document.getElementById("response").innerHTML = xmlhttp.response;
      document.getElementById("response_text").innerHTML = xmlhttp.response;


Text from the XML file are brought over to the HTML from the server. That's a nice feature.

But this fails on my server:

Code:

      xmlDoc=xmlhttp.responseXML;


responseXML has a vale of NULL.

responseXML has a proper XML DOM when the same code with the same XML file is run on my hosted web site.

So I must not have Apache set up properly.

I'm suspecting something wrong with mime.types.

Here is the HTML code that works on my hosted web site, but fails on my system:

Code:

<!DOCTYPE html>
<html>
<body>
<h3>Test of XMLHttpRequest.responseXML</h3>
<div>
   <br />
   Response HTML:
   <p id = "response_html"> </p>
   <br />
   Response:
   <p id = "response"> </p>
   <br />
   Response Text:
   <p id = "response_text"></p>
</div>

<script>
   var error_message;

   try
   {
      if (window.XMLHttpRequest)
      {
         // code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp=new XMLHttpRequest();
      }
      else
      {
         // code for IE6, IE5
         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.open("GET","note.xml",false);
      xmlhttp.send();

      document.getElementById("response").innerHTML = xmlhttp.response;

      document.getElementById("response_text").innerHTML = xmlhttp.response;

      xmlDoc=xmlhttp.responseXML;

      document.getElementById("response_html").innerHTML=
      xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
   }
   catch(err)
   {
      error_message = "Error \n";
      error_message += err.message;
      alert(error_message);
   }

</script>

</body>
</html>


Here is the XML:

Code:

<note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
</note>


Suggestions?

Thanks
Larry
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Fri 30 Nov '12 18:48    Post subject: Reply with quote

For me the code works fine. Are you sure your server send the correct mime type / Content-Type application/xml for the note.xml ?

However I recommend to install firebug in firefox and find the error.
Not all browsers support xmlhttp.responseXML. That is why I use jQuery as framework which chooses the right method.
Back to top
larryl



Joined: 28 Nov 2012
Posts: 3
Location: USA, Portland

PostPosted: Sat 01 Dec '12 8:26    Post subject: Reply with quote

Thanks James:

Yea, I thought this was an Apache configuration issue.

That's why I posted it to the Apache forum. It was moved here, where I don't believe Apache Configuration is on topic.

If Apache is not configured to deliver XML to the script, not delivering it is probably not a bug or a problem.

Do you have any idea what httpd.conf or mime.types entry would enable, or disable, the delivery of the XML tree to the script?

Both FireFox and Chrome have the XML DOM tree when connected to my hosted web site, and have NULL when connected to my test site.

I appreciate your efforts.

Thanks
Larry
Back to top


Reply to topic   Topic: XMLHttpRequest.responseXML isn't working for me. View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner