Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Returning XML data

    I'm trying to use PHP to return an XML document, but I am getting an error saying that the response XML has no properties. When I manually send it to an xml page with hardcoded data though, it works how it's supposed to. I assume this means I am missing a header somewhere to tell the ajax call to treat the php page like an xml document.

    This is what the ajax call looks like:

    Code:
    xmlhttp.open("GET", "ajx_update_contacts.php", true);
    xmlhttp.send(null);
    And with the return data..
    Code:
    var XMLDoc = xmlhttp.responseXML;
    var Nodes = XMLDoc.getElementsByTagName("CONTACT");
    var NumNodes = Nodes.length;
    
    contactsArray.length = 0;
    
    for (var i = 0; i < NumNodes; i++)
    {
      var node_Name = Nodes[i].getElementsByTagName("NAME")[0].firstChild.nodeValue;
      var node_ID  = Nodes[i].getElementsByTagName("ID")[0].firstChild.nodeValue;
      var node_Status  = Nodes[i].getElementsByTagName("STATUS")[0].firstChild.nodeValue;
    
      var newContact = new contact(node_Name, node_ID, node_Status);
      contactsArray[contactsArray.length] = newContact;
    }
    And the php code to create the XML document:

    Code:
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
    header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
    header("Cache-Control: no-cache, must-revalidate" );
    header("Pragma: no-cache" );
    header("Content-Type: text/xml; charset=utf-8");
    
    $XML = '<?xml version="1.0"?>';
    $XML .= "<ROOT>";
    
    while($contactID = mysql_fetch_array($queryContacts))
    {
    	$contact_id = $contactID[0];
    
    	$queryContact = mysql_query("SELECT name, status FROM members WHERE member_id = '" . $contact_id . "'") or die(mysql_error());
    	$contactData = mysql_fetch_array($queryContact)
    
    	$contact_name = $contactData[0];
    	$contact_status = $contactData[1];
    
    	$XML .= "<CONTACT><NAME>" . $contact_name . "</NAME><ID>" . $contact_id . "</ID><STATUS>" . $contact_status . "</STATUS></CONTACT>";
    }
    
    $XML .= "</ROOT>";
    
    echo $XML;

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by bengaltgrs View Post
    Code:
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
    though that looks a bit fishy... did u try accessing the ajx_update_contacts.php page in a browser? does it display like any other static xml file?

    the php script may be silently dying out
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Oct 2007
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts
    With that header taken out and with no headers at all, there is no display when I open ajx_update_contacts.php. What could be causing this?


  •  

    Posting Permissions

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