Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    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
    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]

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its displays "Object required"

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    when it comes to the alert childnodes length, it displays "object required" error in IE, works well in Firefox

    Thanks,
    Tannu

  • #5
    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
    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]

  • #6
    New Coder
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks buddy, it works well now. Problem was with the bad markup returned.

    Tannu


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •