简体   繁体   中英

Edit a file using javascript

I need to edit an xml file using javascript. Now I'm involved in a project of online testing.

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

In that i want to add or edit the questions(only using javascript). I'm able to bring the particular content through ajax, but I am not able to edit the file.

Javascript can't write to a file. The best you'll be able to do is get Javascript to read and edit the XML then post that data to a server-side script to write to file.

Until now, Google Chrome is the only web browser that has a functioning implementation of the FileSystem API, therefore, it may allow you to save files locally using only Javascript.

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

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

Nickf is correct. The reason Javascript can't write to a file is because it is a Client-Side language. Javascript will never have permission to write a file because it has to operate inside the browser sandbox.

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

如果您愿意使用Google Gears ,则会在客户端计算机上获得一个沙箱,可以在其中写入文件。

Javascript has no built-in file I/O (aka you can't do it with JS alone)

Instead use some kind of server side language such as PHP or ASP.NET in conjunction with Javascript's AJAX functionality.

Look over Adobe's Flex development system. There are ways you can use it to build an app that runs in the browser (or not) and can access the filesystem (Windows/Mac/Linux). It's programmed in ActionScript, a dialect of javascript; and can interoperate with javascript in the browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM