KFox
KFox

Reputation: 1266

Write/read a file on the server with AJAX

I know that it probably isn't, but is it possible to write/read a file on the server without server side languages. I've looked in a bunch of places and found oblique references to reading files on the server using XmlHttpRequest. I unfortunately have not found any "good" info on reading files.

I have found absolutely nothing when it comes to writing files without server side languages though. I am somewhat new to coding (4 to 5 months) and started out with HTML/JS, so I don't know any server side languages and when I look at them I get a headache trying to understand. I know AJAX interacts with the server, so I thought there must be some way to write a file on the server with AJAX.

Please tell me if I'm just being naive or if there it actually some truth behind my hypotheses. If there is a way to do so, then it would be nice to give me a link to an explanation or to give me one yourself.

Upvotes: 0

Views: 6418

Answers (3)

Tushar Sharma
Tushar Sharma

Reputation: 347

Well let us understand the concept first.

AJAX is basically used to load the data from the server to the browser behind the scenes.

Next, If i presume that you know how to load the data asynchronously from the server to the browser behind the scenes. You might be using the POST or GET method.

Using the xmlRequestObject.send() function you can send parameters to the server file. But again just sending the data to the server is not enough. There needs to be some code on the server side to take that data and write that. For that you require a scripting language like PHP or use ASP.NET.

In my R&D, I did not find any such techniques that allow writing data to files on server without the use of server side scripting languages. If you find any..Let me know.

Upvotes: 1

Quentin
Quentin

Reputation: 943108

I know that it probably isn't, but is it possible to write/read a file on the server without server side languages.

At a fairly abstract level: You have to have a server. That server has to be written in some language.

All regular web servers support the reading of files from file systems. Generally you specify a directory to be the root, then the local part of the URL gets mapped on to that directory and its sub-directories.

Writing is trickier. The HTTP specification includes the PUT verb, but not many servers have built in support for doing anything useful with it … and you'd almost always want to add some sort of access control before allowing anyone with access to the Internet to write files.

Expressing the logic behing the access control and where the file should be placed is something that is usually most easily handled with a programming language.

I've looked in a bunch of places and found oblique references to reading files on the server using XmlHttpRequest. I unfortunately have not found any "good" info on reading files.

XMLHttpRequest is just the standard API that browsers provide to JavaScript for making HTTP requests. It is entirely client side. You give it a URL, you get the data the server returns in a callback.

I have found absolutely nothing when it comes to writing files without server side languages though. I am somewhat new to coding (4 to 5 months) and started out with HTML/JS, so I don't know any server side languages and when I look at them I get a headache trying to understand.

JavaScript is a server side language. It isn't the easiest one to get to grips with, but it is an option. See node.js.

I'd recommend getting to grips with Python and using Django for someone new to programming.

I lean towards Perl and Catalyst for my own projects.

I know AJAX interacts with the server, so I thought there must be some way to write a file on the server with AJAX.

Ajax just means "Making an HTTP request from JavaScript without leaving the page". You can send a file, but once the request gets to the server, the server has to handle it.

Upvotes: 3

Sturm
Sturm

Reputation: 4285

The simplest method would most likely be to just use ajax to call a php script on the server. PHP is fully capable of reading/writing files on a server.

http://www.tizag.com/phpT/filewrite.php

http://www.tizag.com/ajaxTutorial/ajaxphp.php

Upvotes: 2

Related Questions