|
responseXML in IE
Hi all,
I am having an html page that alerts the length of the XML nodes that are generated using PHP. It works fine in Firefox, but it fails in IE. Please do help me out. I have included the html, js and PHP scripts that i am using.
Following is the html+js i am using:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Tan's AJAX based Blog</title>
<link href="default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function buildAjaxObj()
{
var httpRequest = false;
if(window.XMLHttpRequest)
{
httpRequest = new XMLHttpRequest();
if(httpRequest.overrideMimeType)
httpRequest.overrideMimeType('text/xml');
}
else if(window.ActiveXObject)
{
try
{
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httpRequest;
}
var http = buildAjaxObj();
function initiateProcess()
{
if(http)
{
http.onreadystatechange = handleResponse;
http.open("GET", "query.php");
http.send(null);
}
}
function handleResponse()
{
if(http.readyState == 4)
{
if(http.status == 200)
{
result = http.responseXML;
xmlDocumentElement = result.documentElement;
count = xmlDocumentElement.childNodes[1].firstChild.data;
alert("Length:" + " " + result.getElementsByTagName("topic").length);
if (!result.documentElement && http.responseStream)
{
result.load(http.responseStream);
alert(result.firstChild.childNodes.length);
}
}
}
}
</script>
</head>
<body onload="initiateProcess();">
</body>
</html>
PHP used:
<?php
mysql_connect("localhost", "root", "") or die ("Connection failed");
mysql_select_db("blg") or die ("Cannot connect to the database");
$query = "SELECT * FROM bli";
$result = mysql_query($query);
header("Content-type:text/xml");
$xml = "<topics>";
while($fetchedResult = mysql_fetch_object($result))
{
$xml .= "<topic>";
$xml .= "<topicName>" .$fetchedResult -> topicName. "</topicName>";
$xml .= "<smallDescription>" .$fetchedResult -> smallDescription. "</smallDescription>";
$xml .= "<pubDate>" .$fetchedResult -> pubDate. "</pubDate>";
$xml .= "</topic>";
}
$xml .= "</topics>";
echo $xml;
mysql_free_result($result);
mysql_close();
?>
generated XML:
<topics>
<topic>
<topicName>Blo</topicName>
<smallDescription>Blo</smallDescription>
<pubDate>2007-06-04</pubDate>
</topic>
<topic>
<topicName>Blo</topicName>
<smallDescription>Blo</smallDescription>
<pubDate>2007-06-04</pubDate>
</topic>
<topic>
<topicName>Blo</topicName>
<smallDescription>Blo</smallDescription>
<pubDate>2007-06-04</pubDate>
</topic>
</topics>
Thanks in advance
|