473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

IE6 strange behaviour with fwrite calls

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:

<td><input type="radio" name="CheckMe" onClick='UpdateRecipeID(3);'/></
td>

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"];
?>

(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?
Oct 29 '08 #1
4 1710
Carlo Chiari schreef:
Hi devs,
Hi Carlo,
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:

<td><input type="radio" name="CheckMe" onClick='UpdateRecipeID(3);'/></
td>

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;
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.
>
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");
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?
>
echo "Selezionata ricetta: " .$_REQUEST["id"];
?>

(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?
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
Oct 29 '08 #2
On Oct 29, 6:47*pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Carlo Chiari schreef:
Hi devs,

Hi Carlo,
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:
<td><input type="radio" name="CheckMe" onClick='UpdateRecipeID(3);'/></
td>
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;

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.
* 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");

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?


* echo "Selezionata ricetta: " .$_REQUEST["id"];
?>
(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?

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
Thanx Erwin, tomorrow I'll try your precious suggestions. I'm slightly
new to AJAX world!
Oct 29 '08 #3
phpUrl = "ajax.php?id=" + r_ID + "&amp;sid="+Math.random();
or a timestamp.
Yep, the caching problem. ;-)
Erwin you are right! The problem was fixed adding the random sid. So
is this tecnique needed to fix IE caching problems?
Oct 30 '08 #4
CiAlZ schreef:
>phpUrl = "ajax.php?id=" + r_ID + "&amp;sid="+Math.random();
or a timestamp.
>Yep, the caching problem. ;-)

Erwin you are right! The problem was fixed adding the random sid. So
is this tecnique needed to fix IE caching problems?
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
Oct 30 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniel O'Brien | last post by:
Hi - any help with this would be greatly appreicated - it has already had me confused for a good few hours! I am using Visual Studio 2003 and the .NET framework 1.1. I have a C# Windows...
2
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from...
17
by: SW1 | last post by:
I wrote a small program which does something like tftp - transfering files and some chat, anyway i got a problem with fwrite, here is a snippet of my code: while(length > 0) { putchar('.');...
15
by: Suraj Kurapati | last post by:
Hello, I'm having a rather strange bug with this code: for certain values of 'buf', a segmentation fault occurs when 'free(buf)' is followed by an 'fwrite()'. In the program output, there is no...
6
by: leonecla | last post by:
Hi everybody, I'm facing a very very strange problem with a very very simple C program... My goal should be to write to a binary file some numbers (integers), each one represented as a sequence...
4
by: Nate Murray | last post by:
Hey all, I'm having a strange PHP (4.3.10) problem that seems to have something to do with javascript. This is a bit complex, so hold on to your hats. My issue is that a single function is...
12
by: hemant.gaur | last post by:
I have an application which writes huge number of bytes into the binary files which is just some marshalled data. int len = Data.size(); //arrary size for (int i = 0; i < len; ++i)...
11
by: David Mathog | last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix write, but no fwrite. That is, no portable C method for writing binary data, only system calls which were OS specific. At...
19
by: pal | last post by:
Hi all, Could you help me how to use the fwrite( ) in C ++
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.