-6

$.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".

Alpaca
  • 3
  • 5

1 Answers1

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