www.webdeveloper.com
Results 1 to 2 of 2

Thread: Having Problem with AJAX / xmlHttp.responseXML

  1. #1
    Join Date
    May 2008
    Posts
    4

    Question Having Problem with AJAX / xmlHttp.responseXML

    I am working on a page that makes an ajax request to a php page, the php returns some xml.

    like:

    <?php
    header("Content-type:text/xml");
    header("Cache-Control: no-cache, must-revalidate");
    //A date in the past
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    $q=$_GET["q"];

    include_once("dbconnect.php");
    $sql="SELECT * FROM user WHERE id = ".$q."";

    $result = mysql_query($sql);

    echo '<?xml version="1.0" encoding="ISO-8859-1"?>
    <person>';
    while($row = mysql_fetch_array($result))
    {
    echo "<firstname>" . $row['FirstName'] . "</firstname>";
    echo "<lastname>" . $row['LastName'] . "</lastname>";
    echo "<age>" . $row['Age'] . "</age>";
    echo "<hometown>" . $row['Hometown'] . "</hometown>";
    echo "<job>" . $row['Job'] . "</job>";
    }
    echo "</person>";

    ?>

    and the stateChanged function of javascript code is

    function stateChanged()
    {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    alert(xmlHttp.responseText);
    //here i am checking the responseText and it comes fine....

    var xmlDoc=xmlHttp.responseXML.documentElement;
    //Here responseXML not works. IE shows javascript error Object required

    document.getElementById("firstname").innerHTML=xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;

    document.getElementById("lastname").innerHTML=xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue;

    }
    }


  2. #2
    Join Date
    Dec 2005
    Posts
    193
    I don't know much about ajax and i am just learning. i had the same problem and had to pass each element through an array I hope this helps, maybe somebody will give a better answer or explain the correct way of doing this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles