Hello all,

I'm using AJAX to populate a div tag in my HTML when a drop down list item is selected. It works perfectly in Safari, Firefox, Opera, but fails in IE. The responseText just comes back blank from the php script.

Here's the Javascript it has to deal with:

function GetXmlHttpObject()
{
    xmlHttp = null;
    try
    {
        // Firefox, Opera, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // 6.0+
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); // 5.5+
        }
    }
}

function stateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        var response = xmlHttp.responseText;
        document.getElementById("contentBox").innerHTML=response;
    } 
}

And here's the php script I'm using to fetch some data from the MySQL server:

<?php
    $id = $_GET["id"];
    include('connect.php');
    $theQuery = mysql_query("select post from archive where title='" . $id . "'");
    $row = mysql_fetch_assoc($theQuery);
    echo $row['post'];
?>

Thanks in advance for any help!

One script can't see new objects another script creates. It sees only the original document structure at the time the page opened.

Thanks for such a general answer.

I really have no idea what "script" you're referring to. Do you mean my php script including 'connect.php'? Because that's only information it needs to connect to the server and won't change at all.

Maybe I forgot to mention, or maybe you just forgot to read the part where I said it works in Firefox, Safari, and Opera. I think it's a problem with the way IE is interpreting the document type. Maybe it's trying to parse it before it gets to the page. Again this is only happening in IE so there's nothing wrong with my code, I just need to add something to make it work with IE.

If anybody else runs across this problem, I've come across the solution (thanks to BetaWar on dreamincode.net).

The following is the code I have now. IE wasn't recognizing what this.value was because I didn't have the value attribute in the option tag. I was assuming that "this.value" was being fetched from the text inside the option tags. I assumed wrong I guess.

<select id="post" onchange="changePost(this.value);">
<?php
include('php/connect.php');
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_assoc($result))
{
$id = $row['pk'];
$title = $row['title'];
echo "<option id=\"".$id."\" value=\"".$title."\">".$title."</option>\n";                         }
}
mysql_close($con);
?>
</select>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.