I'm using ajax to read and write to a text file. The code works on Windows, but not in Macintosh. Any suggestions on what is wrong with the code? Thanks much-- a friend wrote me this code, and I don't really understand how it works!
This part of the code appears in the html file, and calls the php file fileReader.php: -
function getContents()
-
{
-
url = "fileReader.php";
-
var browserName = navigator.appName;
-
//for Moz, FF, NN, Op
-
if (browserName.indexOf("Microsoft") == -1)
-
{
-
reqXML = new XMLHttpRequest();
-
}
-
//IE
-
else if (browserName.indexOf("Microsoft") != -1)
-
{
-
reqXML = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
if(reqXML)
-
{
-
reqXML.onreadystatechange = function ()
-
{
-
if(reqXML.readyState == 4){
-
}
-
}
-
reqXML.open("GET", url, true);
-
reqXML.send(null);
-
}
-
return reqXML.responseText;
-
}
-
This part of the code appears in the fileReader.php file: -
<?php
-
-
$myFile = "data.txt";
-
$fh = fopen($myFile, 'r') or die("can't open file");
-
$theData = fread($fh, filesize($myFile));
-
fclose($fh);
-
-
echo $theData;
-
?>
-
This part of the code appears in the html file, and calls the php file fileWriter.php: -
function ajaxCall(response)
-
{
-
url = "fileWriter.php?update=" + response;
-
var browserName = navigator.appName;
-
//for Moz, FF, NN, Op
-
if (browserName.indexOf("Microsoft") == -1)
-
{
-
reqXML = new XMLHttpRequest();
-
reqXML.open("GET", url, true);
-
reqXML.send(null);
-
}
-
//IE
-
else if (browserName.indexOf("Microsoft") != -1)
-
{
-
reqXML = new ActiveXObject("Microsoft.XMLHTTP");
-
if(reqXML)
-
{
-
reqXML.open("GET", url, true);
-
reqXML.send(null);
-
}
-
}
-
Finally, this part of the code appears in the fileWriter.php file: -
<?php
-
-
$update = $_GET['update'];
-
-
$myFile = "data.txt";
-
$fh = fopen($myFile, 'a') or die("can't open file");
-
-
fwrite($fh, $update);
-
-
?>
-
5 1624
Heya, katiebeals. Welcome to TSDN!
I believe [code=javascript] is what you are looking for.
What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Thanks for your reply.
GetContents() isupposed to return a string that consists of the contents of the file data.txt.
ajaxCall(response) is supposed to append the value of the variable response (as string variable) to the file data.txt.
Both js routines [code=js] call the php routines [code=php] I've included in my original post.
Thanks for your reply.
GetContents() isupposed to return a string that consists of the contents of the file data.txt.
ajaxCall(response) is supposed to append the value of the variable response (as string variable) to the file data.txt.
Both js routines [code=js] call the php routines [code=php] I've included in my original post.
For writing, you should use POST rather than GET because it makes a modification and the variable response could be long. See an example of a POST request.
Thanks. I tried changing 'GET' to 'POST' but still no luck.
I now think the problem is that the responseText method is returning a null value in Safari. Does anyone know a way around this?
Heya, Katie.
Try print_r()ing your response to see what's in it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: yawnmoth |
last post by:
i'm trying to read / write a file, and am having some problems...
here's the php script i'm trying to read / write with:
<?
$fp = fopen("test","r+");
while (!feof($fp)) {
$temp=fgets($fp);...
|
by: jeff M via .NET 247 |
last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
|
by: A. Gaubatz |
last post by:
In VB6, I would open files with:
Open <file name> For <input/output/append> As <file number>
I could then use the Write/Input commands to modify/read the file. How
do I do this in VB.NET?
...
|
by: smeenehan |
last post by:
This is a bit of a peculiar problem. First off, this relates to Python
Challenge #12, so if you are attempting those and have yet to finish
#12, as there are potential spoilers here.
I have five...
|
by: lancer6238 |
last post by:
Hi all,
I'm having programs reading from files.
I have a text file "files.txt" that contains the names of the files to
be opened, i.e. the contents of files.txt are
Homo_sapiens.fa...
|
by: RyanL |
last post by:
I'm a newbie with a large number of data files in multiple
directories. I want to uncompress, read, and copy the contents of
each file into one master data file. The code below seems to be doing...
|
by: sandipm |
last post by:
Hi,
I am trying to read a file and write into other file. if I do it for
simple text file, it works well.
but for pdfs or some other mime types, its failing.
actually main problem is i am...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |