tags:

views:

8373

answers:

10

Is there a way to get jquery to get information to and from a file...

let say i ask a question and i like to get the answer in a file.. to keep track..

is it possible? how?

+15  A: 

No. Javascript doesn't have access to writing files as this would be a huge security risk to say the least. If you wanted to get/store information server-side, though, you can certainly make an AJAX call to a PHP/ASP/Python/etc. script that can then get/store the data in the server. If you meant store data on the client machine, this is impossible with Javascript alone. I suspect Flash/Java may be able to, but I am not sure.

If you are only trying to store a small amount of information for an unreliable period of time regarding a specific user, I think you want cookies. I am not sure from your question what you are trying to accomplish, though.

Paolo Bergantino
+4  A: 

Cookies are your best bet. Look for the jquery cookie plugin.

Cookies are designed for this sort of situation -- you want to keep some information about this client on client side. Just be aware that cookies are passed back and forth on every web request so you can't store large amounts of data in there. But just a simple answer to a question should be fine.

Clyde
+4  A: 

You will need to handle your file access through web programming language, such as PHP or ASP.net.

To set this up, you would:

  • Create a script that handles the file reading and writing. This should be visible to the browser.

  • Send jQuery ajax requests to that script that either write data or read data. You would need to pass all of your read/write information through the request parameters. You can learn more about this in the jQuery ajax documentation.

Make sure that you sanitize any data that you are storing, since this could potentially be a security risk. However, this is really just standard flat-file data storage, and is not necessarily that unusual.

As Paolo pointed out, there is no way to directly read/write to a file through jQuery or any other type of javascript.

jonstjohn
+4  A: 

both HTML5 and Google Gears add local storage capabilities, mainly by an embedded SQLite API.

Javier
A: 

OK, my choice will be to do that with PHP... any free framework or lib around to handle the file...

the file will be a .txt with something into like:

itema:65 itemb:456 itemc:12

i will just load that values into an array... and increase the value according to the answer..

make sens ?

marc-andre menard
use json style. it's javascript native and php can read it.
CuSS
A: 

If you want to do this without a bunch of server-side processing within the page, it might be a feasible idea to blow the text value into a hidden field (using PHP). Then you can use jQuery to process the hidden field value.

Whatever floats your boat :)

Josh Stodola
A: 

It depends where are you saving the file. client or server.

A: 

on the server

marc-andre menard
I would either add comments to the origial question, or add to the base question rather than "answers"
Mark Schultheiss
+3  A: 

Yes it is possible.

The technique is described below

http://jquery.tiddlywiki.org/twFile.html

ja
A: 

yes with ajax is posible ive made this with dojo many times

geomorillo
sorry just reading xml
geomorillo