Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 14th, 2005, 4:36 PM   #1
sunny_boy
Newbie
 
Join Date: May 2005
Posts: 2
Rep Power: 0 sunny_boy is on a distinguished road
Exclamation XMLHTTPRequest Help in IE

Hey, I hope I've placed this in the right place. I need help with XMLHTTPRequest and Internet Explorer.

Hokey, a little background. I'm creating a script with mainly PHP & XHTML and I am using XMLHTTPRequest to retrieve data from another PHP script and display it. I've got it to work with the Firefox, Mozilla, Opera and Netscape browser, yet IE does not like it.

I have these JavaScript functions in the head of my page:

<script type="text/javascript">

var req;
function getfileinfo(filename) {
	try {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = showfileinfo;
			req.open ("GET", 'default.php?a=fi&name=' + filename);
			req.send(null);
		}
		else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			req.onreadystatechange = showfileinfo;
			req.open ("GET", 'default.php?a=fi&name=' + filename);
			req.send(null);
		}
		
	} 
	catch (e) {
		alert ("Error: " + e);
	}
}

function showfileinfo() {
	if (req.readyState == 4) {
		if (req.status == 200) {
                        document.getElementById('fileinfo').style.display = 'block';
			var response = req.responseXML.documentElement;
			
			var type = response.getElementsByTagName('type')[0].firstChild.data;
			document.getElementById('fileinfotype').childNodes[0].nodeValue = type;
			
			var description = response.getElementsByTagName('description')[0].firstChild.data;
			document.getElementById('fileinfodesc').childNodes[0].nodeValue = description;
			//document.getElementById('fileinfo').childNodes[0].nodeValue = response;
		}
	}
}
</script>

The first function sends the request to the PHP script and calls in the second function to display it. The second function gets some <span>'s from within the <div> named "fileinfo" and uses the XML values from the PHP script ("default.php?a=fi&name=") to echo them. The PHP script to echo the XML goes as:

[PHP]<?php
header ("Content-Type: text/xml");

$file = $_GET['name'];

echo("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<response>
<type>" . $file . "</type>
<description>" . $file . "</description>
</response>");

return 0;
?>
[/PHP]

The above XML is just to test, and will be modified with time. Hokey, my problem? IE does not display the information in the <div> named "fileinfo" but it does go as far as displaying the <div>, but goes no further. Here is the error I get from IE:

Line: 43
Char: 4
Error: 'document.getElementById(...).childNodes.0' is null or not an object
Code: 0

The bit where the <div> is shown goes as follows:

<div id="fileinfo">

<span id="fileinfotype"> </span>
<span id="fileinfodesc"> </span>

</div>

If anyone can help me, it'd be apreciated. If you have MSN, please add me if you have a solution: sunnyboy01235@gmail.com.

Thanks in advance,
Sunny
sunny_boy is offline   Reply With Quote
Old May 15th, 2005, 7:29 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Can I ask why you don't just read the XML file using PHP? Or why you're even generating one in the first place?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 15th, 2005, 7:34 AM   #3
sunny_boy
Newbie
 
Join Date: May 2005
Posts: 2
Rep Power: 0 sunny_boy is on a distinguished road
The XML file is generated using the PHP. It'd be changed everytime a different link is clicked - the output is different for each of my linkc clicked and is independant on the link.
sunny_boy is offline   Reply With Quote
Old May 15th, 2005, 7:43 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I see. In that case, I don't think I can help you - I have no experience with XMLHTTPRequest. Anyone else?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 25th, 2005, 11:33 AM   #5
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Line: 43
Char: 4
Error: 'document.getElementById(...).childNodes.0' is null or not an object
Code: 0
What was in the '...', and which is line 43? I don't think its an XmlHTTPRequest problem, so you might want to re-phrase the title.
Cerulean is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC