/    Sign up×
Community /Pin to ProfileBookmark

Possible to write to file with Ajax and open("POST"……?

Hello all!
Is it possible to write to a file on the server end just with JavaScript?
When I want to POST to my server, can I write to a file in a similar manner as GET?

[CODE]var http = new XMLHttpRequest();
http.open(“POST”, “http://localhost/apache2-default/post.txt”, false);
http.send(“I write!!”);
if(http.status == 200)
{
alert(“Written ok!”);
}
else
{
alert(“Error while reading file!”);
}[/CODE]

I get the alert “Written ok! ” but nothing happens if there is a file called “post.txt” already in folder, nothing written in file though. If the file does not exist I get the error.

Please get me on the right track!!

Many thanks!
Marcus

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@toenailsinFeb 03.2008 — i doubt there wuld be a way to do that with javascript alone. you'd need some server-side scripting to get the POST and edit the file
Copy linkTweet thisAlerts:
@A1ien51Feb 03.2008 — POST and GET are meant to retrieve and send data. There are no http methods to write data. As mentioned before you would have to use a serverside language to write to a file.

Eric
×

Success!

Help @marcux spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...