Advertisement

10.07.2008 at 01:45AM PDT, ID: 23793011 | Points: 500
[x]
Attachment Details

Having Problem with AJAX / xmlHttp.responseXML

Asked by mysticamusic in Asynchronous Javascript and XML (AJAX), PHP for Windows, PHP and Databases

Tags: , ,

I am working on  a page that makes an ajax request to a php page, the php returns some xml.

like:

<?php
header("Content-type:text/xml");
header("Cache-Control: no-cache, must-revalidate");
//A date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

$q=$_GET["q"];

include_once("dbconnect.php");
$sql="SELECT * FROM user WHERE id = ".$q."";

$result = mysql_query($sql);

echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<person>';
while($row = mysql_fetch_array($result))
 {
 echo "<firstname>" . $row['FirstName'] . "</firstname>";
 echo "<lastname>" . $row['LastName'] . "</lastname>";
 echo "<age>" . $row['Age'] . "</age>";
 echo "<hometown>" . $row['Hometown'] . "</hometown>";
 echo "<job>" . $row['Job'] . "</job>";
 }
echo "</person>";

?>

and  the stateChanged function of javascript code is

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
alert(xmlHttp.responseText);
//here i am checking the responseText and it comes fine....

var xmlDoc=xmlHttp.responseXML.documentElement;
//Here responseXML not works. IE shows javascript error Object required

document.getElementById("firstname").innerHTML=xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;

 document.getElementById("lastname").innerHTML=xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue;

}
}
Start Free Trial
[+][-]10.07.2008 at 04:54AM PDT, ID: 22658378

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.07.2008 at 04:55AM PDT, ID: 22658384

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.09.2008 at 11:12PM PDT, ID: 22684605

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.12.2008 at 03:20AM PST, ID: 22938414

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628