...

responseXML in IE

tannu
06-05-2007, 03:42 PM
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

A1ien51
06-06-2007, 03:14 PM
You need to say what the error is. Just saynig it does not work does not help.

Eric

tannu
06-09-2007, 08:11 AM
Its displays "Object required"

tannu
06-09-2007, 08:13 AM
when it comes to the alert childnodes length, it displays "object required" error in IE, works well in Firefox

Thanks,
Tannu

A1ien51
06-10-2007, 01:59 AM
well your XML is not valid if you do not have the <?xml version="1.0" encoding="ISO-8859-1"?> line in your output

Also tips on debugging ResponseXML here:
http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html

Eric

tannu
06-11-2007, 07:52 AM
Thanks buddy, it works well now. Problem was with the bad markup returned.

Tannu



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum