I have some JSON scripts that I plan on parsing on the site and then allowing the clients to edit them through my interface (to later be loaded and parsed once again for display). Problem is, Javascript doesn’t have access to writing to the file system. I’ve already got a system for reading the JSON files using Javascript (and jQuery). Now, I’ve heard I can use CGI to save the data later. Can somebody give me some references and in depth explanations? I’ve read a bit about CGI in general but nothing specific.
Thanks for any help!
CGI is a way for servers to interface with scripts. Pretty much, you just set up the server to execute a file, and it will execute it with several environment variables set and POST data fed to its standard input. The script should output the headers for the page, followed by the content.
CGI scripts can be written in many different languages. Perl is well-known for CGI scripts; it has documentation on it here. Python has a
cgimodule to deal with CGI. Ruby has aCGIpackage as well.Here’s a quick CGI script written in Python that writes to a file. You’ll probably want to modify it or use it as a reference rather than using it as-is:
If you
POSTto it with adataparameter, it will save that data intosome_file.jsonin the same directory as itself.