Skip to content Skip to sidebar Skip to footer

Read/write Json From Js To File On Server (not Server App)

I'm working with a .js client and have and object that I need to write out to a file on the server. A couple of questions - file i/o with JavaScript is new to me... I was planning

Solution 1:

  1. You can open a file located on the server via ajax by querying the file and loading it into a JSON object. You might want to LINT your JSON

  2. You can not write to an object on the server via the client. This is a severe security breach. Common practice is to change the JSON data and then send it via ajax to server-side code. The server will then do the file IO.

  3. Yes using JSON.parse otherwise eval is indeed correct. I would recommend json2.js

  4. The data should be fine as long as it passes JSONLint.

Your main issue is that it's impossible to write to the server from the client. Get the client to load the data through ajax change it and then query the server to update the file.

Solution 2:

js don't have i/o property;

you should use ajax or http request to send message to server,and tell server to do de i/o action...

Post a Comment for "Read/write Json From Js To File On Server (not Server App)"