Hello, first of all, I would like to clarify that I looked so much here in the stack, as in other sites something that answered my question, but I did not find it. My question is, how can I rewrite the contents of a JSON file from the server using AJAX? In case, I can get the contents of it and use it in the browser normally, but when I change something in the browser, I would like to save / overwrite the changes in the original file.
Current Code:
JSON
[{
"nome":"Borin Gnur",
"profissao":"Bibliotecário",
"imagem":"img/borin.png"
}, (...)]
JS
var personagensJSON;
function recuperaPersonagens(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
return personagensJSON = JSON.parse(this.responseText);
}
};
xhttp.open("GET", "personagens.json", true);
xhttp.send();
//selecaoPersonagem();
}