responseText is empty in IE

Thread Solved

Join Date: Jan 2006
Posts: 14
Reputation: drago865 is an unknown quantity at this point 
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

responseText is empty in IE

 
0
  #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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function GetXmlHttpObject()
  2. {
  3. xmlHttp = null;
  4. try
  5. {
  6. // Firefox, Opera, Safari
  7. xmlHttp=new XMLHttpRequest();
  8. }
  9. catch (e)
  10. {
  11. // Internet Explorer
  12. try
  13. {
  14. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // 6.0+
  15. }
  16. catch (e)
  17. {
  18. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); // 5.5+
  19. }
  20. }
  21. }
  22.  
  23. function stateChanged()
  24. {
  25. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  26. {
  27. var response = xmlHttp.responseText;
  28. document.getElementById("contentBox").innerHTML=response;
  29. }
  30. }

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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. $id = $_GET["id"];
  3. include('connect.php');
  4. $theQuery = mysql_query("select post from archive where title='" . $id . "'");
  5. $row = mysql_fetch_assoc($theQuery);
  6. echo $row['post'];
  7. ?>

Thanks in advance for any help!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,266
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 171
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: responseText is empty in IE

 
0
  #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 Quick reply to this message  
Join Date: Jan 2006
Posts: 14
Reputation: drago865 is an unknown quantity at this point 
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

Re: responseText is empty in IE

 
0
  #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 Quick reply to this message  
Join Date: Jan 2006
Posts: 14
Reputation: drago865 is an unknown quantity at this point 
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

Re: responseText is empty in IE

 
0
  #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.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



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


Views: 4053 | Replies: 3
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC