Editing a file with javascript

I need to edit the xml file using javascript. I am now participating in an online testing project.

The question.xml file is already in the project folder.

Is that I want to add or change questions (using javascript only). I can pass specific content via ajax, but I cannot edit the file.

0


source to share


6 answers


Javascript cannot write the file. The best you can do is get the Javascript to read and edit the XML, and then send that data to a server-side script to write to a file.



+5


source


So far, Google Chrome is the only web browser that has a functional implementation of the FileSystem API, so it can let you save files locally using only Javascript.

Obviously, for security reasons, when writing files to the local file system, the user must explicitly allow this.



Working tutorial: http://www.html5rocks.com/en/tutorials/file/filesystem/

+1


source


Nickf is correct. The reason Javascript cannot write to file is because it is Client-Side . Javascript will never have write access to the file as it needs to run in the browser sandbox.

You will need a server-side script (.NET, PHP, ColdFusion, etc.) to write the file.

0


source


If you want to use Google Gears , you get a sandbox on the client machine that you can write files to.

0


source


Javascript has no native file I / O (aka, you cannot do this with JS)

Instead, use some server side language like PHP or ASP.NET combined with Javascript AJAX functionality.

0


source


Take a look at the Adobe Flex development system. There are ways to use it to create an application that runs in a browser (or not) and can access the file system (Windows / Mac / Linux). It is programmed in ActionScript, a javascript dialect; and can interact with javascript in the browser.

0


source







All Articles