$.getJSON let us to get data from the file, is there any way to set data into the file? i have tried $.setJSON, but it shows me "$.setJSON is not a function".
Asked
Active
Viewed 254 times
-6
-
ref https://stackoverflow.com/a/21016088/9007957 – programtreasures Feb 13 '18 at 07:38
-
You mean accessing the local files ? – Vignesh Raja Feb 13 '18 at 07:39
-
i created a web application using visual studio, and i want to retrieve and update the json file (data.json). record.html and data.json file is in the same directory. – Alpaca Feb 13 '18 at 07:43
1 Answers
0
You can't access the local file system using front-end Javascript. And there is no way on doing it.
What you can do is create a web server. Send a request with the data in the server using AJAX On the server, save the data by writing it on a file
That's pretty much it.

CodeLover
- 571
- 2
- 11
-
i think that is not true, because i can access the local file system and retrieve the content in the data.json. – Alpaca Feb 13 '18 at 07:54
-
Based on what you want, what I mean is, you can't write to a file using front-end JS. – CodeLover Feb 13 '18 at 07:56
-
You can access a selected file using an input `type=file` so this answer is wrong. You can't write a file, that is right. – Alon Eitan Feb 13 '18 at 08:30
-
so, if i use ajax to pass data to .cs file, is it allow me to save the data to data.json file? – Alpaca Feb 13 '18 at 08:47
-
.cs (CSharp) is out of context here. What I am trying to say is, we use AJAX (XMLHttpRequest) to post our data to the server (in whatever language it may be written) and save it there in a file – CodeLover Feb 13 '18 at 08:49