I want to change my JSON file or add an element to my SON file, but real file. I tried this code, but it doesn't work on the real file. Only the time the tab is open on the web has changed. How to handle it in real file? Not user file, it is server file, but I tried my local.
let xmlreq = new XMLHttpRequest()
xmlreq.open("GET","users.json",true)
function test(){
const obj = JSON.parse(xmlreq.responseText);
console.log(obj);
obj.user1.name="john";
console.log('obj.user1.name: ', obj.user1.name);
obj.user2.push("item");
console.log('obj.user2.: ', obj.user2);
}
xmlreq.send()
another
let xmlreq = new XMLHttpRequest()
function test(){
// let parsereq= JSON.parse(xmlreq.responseText);
const obj = JSON.parse(xmlreq.responseText);
console.log(obj);
obj.user1.name="john";
console.log('obj.user1.name: ', obj.user1.name);
obj.user2.push("item");
console.log('obj.user2.: ', obj.user2);
}
xmlreq.open("GET","users.json",true)
xmlreq.send()