Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2007, 06:14 PM   PM User | #1
bengaltgrs
New Coder

 
Join Date: Oct 2007
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
bengaltgrs is an unknown quantity at this point
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;
bengaltgrs is offline   Reply With Quote
Old 11-09-2007, 06:38 PM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
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
shyam is offline   Reply With Quote
Old 11-09-2007, 10:00 PM   PM User | #3
bengaltgrs
New Coder

 
Join Date: Oct 2007
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
bengaltgrs is an unknown quantity at this point
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?
bengaltgrs is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 PM.


Advertisement
Log in to turn off these ads.