-1
Hello, first, I would like to clarify that I searched both here in the stack, as in other sites something that answered my question, but I did not find. My question is, how can I rewrite the contents of a server JSON file using AJAX? In this case, I can take its content and use it in the browser normally, however, when changing 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();
}
You will need a server-side language analyzing the request and writing to the file. With PHP, you could use
file_put_contents
, for example.– Woss
Dude, I already explained to you in chat that this is impossible.
– Jéf Bueno
I didn’t say I don’t want to use PHP, I said for now I’m not using, precisely why I posted the question, to figure out a way to do this '-'
– Murilo Melo
@LINQ, so I posted the question, to see what options I have with other languages '-'
– Murilo Melo
@Andersoncarloswoss Perl :p
– Jéf Bueno
PERL and PHP as far as I know
– Murilo Melo
any of the languages, in the question, I just left informed that I did not use PHP at any time
– Murilo Melo
I removed from there not to cause more confusion aheuahe
– Murilo Melo
Now another detail: are you already making a POST request with the new data to the server or have difficulty in this part too? If yes, you can ask the question?
– Woss
just like it is in the question, I want to know how to accomplish it, change the content and such, I’m not making any further request
– Murilo Melo