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.ph
p");
$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=="compl
ete")
{
alert(xmlHttp.responseText
);
//here i am checking the responseText and it comes fine....
var xmlDoc=xmlHttp.responseXML
.documentE
lement;
//Here responseXML not works. IE shows javascript error Object required
document.getElementById("f
irstname")
.innerHTML
=xmlDoc.ge
tElementsB
yTagName("
firstname"
)[0].child
Nodes[0].n
odeValue;
document.getElementById("l
astname").
innerHTML=
xmlDoc.get
ElementsBy
TagName("l
astname")[
0].childNo
des[0].nod
eValue;
}
}
Start Free Trial