View Full Version : Ajax / responseText and IE question

03-02-2006, 07:19 PM
I'm getting a string of text back from a php file during an ajax operation. The string is something like "<p>text</p>". When I do this:

response = request.responseText;
myDiv.innerHTML = response;

the innerHTML line fails out in IE but not Mozzy. Any idea why? The response alerts as a legit string of text, but IE will not deal with it - get the old "unknown runtime error" (like thats a lot of help, sheesh) at the innerHTML line in the debugger.

I tried setting the response toString() but that did not help.

03-02-2006, 07:28 PM
I'm not currentl aware of any problems with IE getting responseText, so I'm just gonna try to help you debug.

Have you tried getting any of the other response members like XML, body, etc? What have the results been.

Can you alert anything within the callback you've defined? Can you alert the request variable?

Sorry I can't give you the silver bullet right now, but if you're willing to test some things out, I think we can figure it out.

03-02-2006, 07:31 PM
I'm willing! I probably changed my post just as you posted - reread what I wrote. The problem is the responsetext string is indeed there (I can alert it in IE) but when applied to the element.innerHTML - boom. I can't imagine why this would be an issue...

I set my processing php file to header("Content-type: text/html") as well...

03-02-2006, 07:36 PM
Here is the page:


here is the php:

header("Content-type: text/plain");
class DB {

var $ident;
var $sql = array('host'=>'h','user'=>'u','pass'=>'pw','db'=>'db');

function connect ()
// Connect to MySQL
$this->ident = mysql_connect($this->sql['host'], $this->sql['user'], $this->sql['pass']);

// Select assigned DB
if (!mysql_select_db($this->sql['db'])) {
die("Could not connect to DB");

function disconnect ()
// Close the connection
if (!mysql_close($this->ident)) {
die("Could not close DB");


$DB = new DB();

// Connect with info

// get data
$mname = $_GET['mname'];
$mmail = $_GET['mmail'];

//echo "$mname $mmail";
$strResponse = "";

$result = mysql_query("INSERT INTO ctmembers(name, email) VALUES ('$mname', '$mmail')");
if (!$result) {
die('Invalid query: ' . mysql_error());
$strResponse = "<p>We're sorry but there is a problem with our mailing list. Please try again later.</p>";
//TODO: Send myself a notification that there is a failure.
$strResponse = "<p>You have successfully been added to the mailing list.</p>";

// Close connection

echo $strResponse;

03-02-2006, 07:45 PM
IE does have some issues with trying to manipulate the dom when it's not ready for you to do so.

Try pulling the "Working..." text out of the readystatechange == 2 || 3, that get's called constantly, when really it only needs to be called once. You could be having multiple asynchronous writes occuring to the element, which would result in IE having a coniption.

Try that, see if it works.

03-02-2006, 07:48 PM
Ok, solved it - and get this one: I changed:

$strResponse = "<p>We're sorry but there is a problem with our mailing list. Please try again later.</p>";

to this

$strResponse = '<p>We\'re sorry but there is a problem with our mailing list. Please try again later.</p>';

Switched from double to single quotes in the php processing page. I don't know what this matters to IE, but somehow it does! Now that is wacky.

03-02-2006, 07:53 PM
Yes, indeed...

Just for grins, if you would, try using double quotes but still escaping that single quote.

03-02-2006, 07:55 PM
Yep that works too - it was the darn apostrophe! :P

03-02-2006, 07:58 PM
Well, hmmm, I can't remember, but aren't apostrophe and double-quote special character in html that need to be represented by the HTML entities &apos; and &quot; ?? I've never run into it, but it could be that the JScript engine in IE requires those.


Well, at least you found it.

03-02-2006, 10:17 PM
Either using the entity values or escaping them will work.