Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2008

    Parsing responseXML

    I'm just getting started with Ajax, and because of an issue that I have trying to get javascript to execute from innerHTML, I wanted to test using XML and parse it into the DOM.

    I've looked at a few examples and it seemed easy enough, but I just can't seem to get it to work.

    Here is what I'm doing.

    I've got this simple PHP page returning some test xml. This would be pulling values from the database in production.

    header('Content-Type: text/xml');
    <?xml version="1.0" encoding="utf-8"?>
    	<h3 id="test" class="success">This is a test.</h3>
    	<p id="normal" class="normal">blah blah blah blah blab blahblah blah blah blah blab blahblah blah blah blah blab blah</p>
    Now I have the following javascript, just trying to get at the first node to try to get some data.

    function parseXMLResponse(request, target) {
    	if(request.readyState == 4) {
    		if(request.status == 200 || request.status == 304) {
    			var data = request.responseXML;
    		} else {
    The error I'm receiving is: data.getElementsByTagName("response")[0] has no properties.

    The alert on the responseText shows what appears to be a valid XML document, and you can see that I'm setting the mime-type to text/xml in the php. I'm sending the data using a post from a form because that's how this particular piece will work in production. Could that possibly mess with it? Here is the send code:

    function sendData(data,script,target) {
    	var request = getAjaxObject();
    	if(request) {
    		request.onreadystatechange = function() {
    		request.open("POST", script, true);
    		return true;
    	} else {
    		return false;
    I've also tried setting data to data = request.responseXML.documentElement; and I get the same issue. Can anyone give me a tip to what I may be doing wrong? I appreciate the feedback.


  2. #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Between DC and Baltimore In a Cave
    If you open up the XML document directly in the browser, does it open up correctly?

    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  3. #3
    New to the CF scene
    Join Date
    Feb 2008
    Yeah. I gave that a try earlier just in case the xml was malformed or something. It opened just fine.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts