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 06-05-2007, 03:42 PM   PM User | #1
tannu
New Coder

 
Join Date: Feb 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tannu is an unknown quantity at this point
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
tannu is offline   Reply With Quote
Old 06-06-2007, 03:14 PM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
You need to say what the error is. Just saynig it does not work does not help.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 06-09-2007, 08:11 AM   PM User | #3
tannu
New Coder

 
Join Date: Feb 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tannu is an unknown quantity at this point
Its displays "Object required"
tannu is offline   Reply With Quote
Old 06-09-2007, 08:13 AM   PM User | #4
tannu
New Coder

 
Join Date: Feb 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tannu is an unknown quantity at this point
when it comes to the alert childnodes length, it displays "object required" error in IE, works well in Firefox

Thanks,
Tannu
tannu is offline   Reply With Quote
Old 06-10-2007, 01:59 AM   PM User | #5
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
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/pascarell...096122600.html

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 06-11-2007, 07:52 AM   PM User | #6
tannu
New Coder

 
Join Date: Feb 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tannu is an unknown quantity at this point
Thanks buddy, it works well now. Problem was with the bad markup returned.

Tannu
tannu 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:57 PM.


Advertisement
Log in to turn off these ads.