Click here to get back home

IE6 strange behaviour with fwrite calls

 HomeNewsGroups | Search

comp.lang.php - PHP programming language discussions 

get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
IE6 strange behaviour with fwrite calls Carlo Chiari 10-29-2008
Posted by Carlo Chiari on October 29, 2008, 1:32 pm
Please log in for more thread options
Hi devs,
in my application I need to update a simple text file every time the
user checks an item of a radio group.
I use AJAX method to do this stuff.

In the start page I have this code for evely row:

show/hide quoted text

The UpdateRecipeID() method launches an AJAX request.

function UpdateRecipeID(r_ID)
{
var xmlHttp = getXMLHttp();
var phpUrl;
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse(xmlHttp.responseText);
}
}
phpUrl = "ajax.php?id=" + r_ID;

xmlHttp.open("GET", phpUrl, true);
xmlHttp.send(null);
}

function HandleResponse(response)
{
document.getElementById('ResponseDiv').innerHTML = response;
}

The php code is very simple: (ajax.php)

<?php
require_once("mylibrary.inc.php");
WriteTextFile($_REQUEST["id"],"bridge.txt");

echo "Selezionata ricetta: " .$_REQUEST["id"];
show/hide quoted text

(mylibrary.inc.php)
function WriteTextFile($stream, $fname)
{
        $handle = fopen($fname, 'w');
        if (!$handle ) {
echo "Cannot open file ($fname)";
exit;
        }
        fwrite($handle, $stream);

        fclose($handle);
}

This source code works fine with Safari 3 and Chrome too, but with IE6
works only for the first three times I click a row.

Anyone knows where's the problem?

Posted by Erwin Moller on October 29, 2008, 1:47 pm
Please log in for more thread options
Carlo Chiari schreef:
show/hide quoted text

Hi Carlo,

show/hide quoted text

That is bad.
You will get a cached response back in most circumstances.
Add something random to it to avoid caching:
eg:
phpUrl = "ajax.php?id=" + r_ID + "&amp;sid="+Math.random();

or a timestamp.

show/hide quoted text

Using $_REQUEST is bad in my opinion. It only shows you don't know where
the data comes from.
Why not simply use $_GET instead?

show/hide quoted text

Yep, the caching problem. ;-)

Good luck fixing it. (Just add the Math.random() thingy to it)

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Posted by Carlo Chiari on October 29, 2008, 3:36 pm
Please log in for more thread options
On Oct 29, 6:47=A0pm, Erwin Moller
show/hide quoted text

Thanx Erwin, tomorrow I'll try your precious suggestions. I'm slightly
new to AJAX world!

Posted by CiAlZ on October 30, 2008, 3:28 am
Please log in for more thread options

show/hide quoted text

show/hide quoted text

Erwin you are right! The problem was fixed adding the random sid. So
is this tecnique needed to fix IE caching problems?

Posted by Erwin Moller on October 30, 2008, 4:54 am
Please log in for more thread options
CiAlZ schreef:
show/hide quoted text

Yes. But the problem is not limitted to IE only, so always use this trick.

Glad it works.

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Similar ThreadsPosted
fwrite - Linux and ISP - Very Strange! July 9, 2005, 2:16 pm
strange repeating of fwrite (because of javascript?) April 24, 2006, 1:57 pm
mysql strange behaviour August 30, 2005, 11:58 am
Strange behaviour of shell_exec March 15, 2006, 8:03 pm
PHPeclipse - strange behaviour May 29, 2006, 11:19 am
strange POST vs GET behaviour December 27, 2006, 2:46 pm
Strange behaviour with ' char October 29, 2007, 6:58 am
Strange behaviour with ' char October 29, 2007, 6:58 am
Regural expression strange behaviour January 18, 2005, 11:20 pm
redirect page: strange behaviour February 7, 2005, 1:00 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap
Privacy Policy