-2

I can read/open it but don't know how to update the specific value in it.

My data.txt is like

[
  {"slot": "1", "name": "Bob"},
  {"slot": "2", "name": "John"}
]

then i want to update it like query the database "UPDATE data.txt SET name='James' WHERE slot=2"

After update, I want data.txt to be like

[
   {"slot": "1", "name": "Bob"},
   {"slot": "2", "name": "James"}
]

How can I do this with javascript, Ajax, Jquery

Mivaweb
  • 5,580
  • 3
  • 27
  • 53
  • why using the extension .txt and not .json? – Mivaweb May 21 '14 at 09:07
  • read this http://stackoverflow.com/questions/14795357/javascript-in-html-write-to-file .. about the logic of the update and the structure of the text, you have to implement it manually in js – CME64 May 21 '14 at 09:07

1 Answers1

1

You can't do this with a flat file, you need some form of REST-type interface that allows you to query and update the file, I suggest you switch to a database; seeing as you already seem to know how to do it if it was a database.

Entropy
  • 64
  • 1
  • 4
  • I use it to store the data while my application is in offline mode. so i cannot use the database. –  May 21 '14 at 09:11