Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to edit the json file at client side
    primarykey
    data
    text
    <p>i want to edit an json file using javascript. the file is "client.json" and is at the local system and is modified at local system only. I am using form for creating the new client details and i want that those details to be appended to the json file as the object.</p> <pre><code> {"clients":[ { "name":"xxxx", "team":"yyy", "location": { "city":"beijing", "country":"china" }, "wdays":{"start":"Monday","end":"friday"}, "whours":{"start":"9 A.M","end":"6 P.M" } }, { "name":"xxxx", "team":"yyy", "location": { "city":"new york", "country":"usa" }, "wdays":{"start":"Monday","end":"friday"}, "whours":{"start":"9 A.M","end":"6 P.M" } } ]} </code></pre> <p>the following the javascript code is about reading data from form and appending that data as the json object.........`</p> <pre><code>&lt;/script&gt; &lt;script type="text/javascript"&gt; function addtojson() { var client_name=(document.getElementById("cname")).value; var country=document.getElementById("country").value; var city=document.getElementById("city").value; var wtimeto=document.getElementById("wtimeto").value; var wtimefrom=document.getElementById("wtimefrom").value; var wdayto=document.getElementById("wdayto").value; var wdayfrom=document.getElementById("wdayfrom").value; jQuery.getJSON('client.json') .done(function(data) { var cobj=new Object(); cobj.name=client_name; cobj.team="YYY"; cobj.location=new Object(); cobj.location.city=city; cobj.location.country=country; cobj.wdays=new Object(); cobj.wdays.start=wdayto; cobj.wdays.end=wdayfrom; cobj.whours=new Object(); cobj.whours.start=wtimeto; cobj.whours.end=wtimefrom; var myString = JSON.stringify(cobj); alert('I am working'); alert(myString); data.clients.push(cobj); alert(JSON.stringify(data.clients[0]));//it gives previous first array object alert(JSON.stringify(data.clients[1]));//it gives previous second array object alert(JSON.stringify(data.clients[2]));//it gives the new appended array object }); return true; } &lt;/script&gt;` </code></pre> <p>though the data is being modified locally in the program the json file is not getting updated????????</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload