Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   XMLHTTPRequest Help in IE (http://www.programmingforums.org/showthread.php?t=3908)

sunny_boy May 14th, 2005 5:36 PM

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

Ooble May 15th, 2005 8:29 AM

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?

sunny_boy May 15th, 2005 8:34 AM

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.

Ooble May 15th, 2005 8:43 AM

I see. In that case, I don't think I can help you - I have no experience with XMLHTTPRequest. Anyone else?

Cerulean Jun 25th, 2005 12:33 PM

:

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.


All times are GMT -5. The time now is 12:58 AM.

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