User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,610 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,608 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 997 | Replies: 3 | Solved
Reply
Join Date: Jan 2006
Posts: 13
Reputation: drago865 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

responseText is empty in IE

  #1  
Jun 8th, 2008
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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,510
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 103
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: responseText is empty in IE

  #2  
Jun 10th, 2008
One script can't see new objects another script creates. It sees only the original document structure at the time the page opened.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jan 2006
Posts: 13
Reputation: drago865 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

Re: responseText is empty in IE

  #3  
Jun 10th, 2008
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.
Reply With Quote  
Join Date: Jan 2006
Posts: 13
Reputation: drago865 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

Re: responseText is empty in IE

  #4  
Jun 10th, 2008
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.

  1. <select id="post" onchange="changePost(this.value);">
  2. <?php
  3. include('php/connect.php');
  4. if(mysql_num_rows($result) > 0)
  5. {
  6. while($row = mysql_fetch_assoc($result))
  7. {
  8. $id = $row['pk'];
  9. $title = $row['title'];
  10. echo "<option id=\"".$id."\" value=\"".$title."\">".$title."</option>\n"; }
  11. }
  12. mysql_close($con);
  13. ?>
  14. </select>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 12:13 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC