Javascript Write To Textfile
Solution 1:
The problem with this is simple: Lets say a developper created javascript code to go through all your filesystem and populate it with dummy files, ruining your hard drive in the process? That is why javascript won't allow you to do this kind of operation. When we want to save information, usually, its done using server-side code and not the client's computer (unless of course we are talking about things like cookies).
The point of my answer is to let you rethink who does the saving and to where. It should be up to the server to save and retain any information for a user, and so you would not write this kind of javascript code... It is best to save data somewhere your client cannot control or edit, like on the server for instance.
I could suggest some easy PHP code, and instead of storing inside a text file, try a database... PHP is a server-side language which will let you save things to files on your server computer, however your server must be able to run PHP, most computers don't come built in with the PHP language and so you will also need a webserver with php built-in..
Solution 2:
In my opinion your entire approach is bad; you need to learn PHP and mySQL to store and load persistent data. - Edit: accessing the file system from JavaScript is a huge security risk and therefore not allowed in general. Unless your goal is specifically to write files from JS, there are better alternatives.
Anyway, this code will only work on Internet Explorer, and only with the security settings way down. You shouldn't pursue this though.
If your end goal is to write a web app that stores and displays reservations, get XAMPP and find a beginner PHP + database tutorial.
Post a Comment for "Javascript Write To Textfile"