views:

30

answers:

3

Hi!

I'm using AJAX with PHP to read from a file and update the div's innerHTML. It works on Chrome and Firefox, but not in Internet Explorer.

I tried to use:

But I think it is useless, since I'm not refreshing the page.


if(!$newMsg || $newMsg == "") { // only reading from the file
    // do nothing
} else {
    $fileData .= "$newMsg";

    fwrite($fileHandler, "$newMsg");
}

fclose($fileHandler);

echo $fileData;

Interesting that when it enters the "else" block, it shows the file's content updated. But when it enters the "if" block, it shows the old content.

+4  A: 

The problem is not in PHP, it is in the browser. PHP is only run on the server side so the browser doesn't matter at all. I suspect a problem in some of your JS code.

Emil Vikström
A: 

The problem is in your JS code which is sending some value to PHP. IE is not able to construe it. Do post your JS code and also did you debug your code.

Use DebugBar

http://www.debugbar.com/?langage=en

Vinothbabu
A: 

The problem is that IE was caching. It was showing the content of the file based on the URL. Example:

script.php?msg=&fileName=myfile.txt

The msg is always empty when it is only updating. So I add a counter as parameter:

script.php?msg=&fileName=myfile.txt&counter=1

Now it is working in IE.

One funny thing to mention: when you send the same msg, IE shows the content until the first time you sent the message. That's how I realized the problem.

Leandro