![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 2
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2005
Posts: 2
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I see. In that case, I don't think I can help you - I have no experience with XMLHTTPRequest. Anyone else?
|
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Line: 43 Char: 4 Error: 'document.getElementById(...).childNodes.0' is null or not an object Code: 0 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|