I want to load 2 json files:
number.json : {"argent":300,"nbJoueur":11,"nbClub":1,"nbVictoire":0,"nbDefaite":0}
img.json : {"bonus1":false,"bonus2":false,"bonus3":false,"bonus4":false,"bonus5":false,"bonus6":false}
I managed to read the first file, but I don't know what to do to read the second file in the same time.
I have this code :
Javascript :
function load(){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (this.readyState === 4 && this.status === 200){
var recup = JSON.parse(this.responseText);
number["argent"] = recup["argent"];
number["nbJoueur"] = recup["nbJoueur"];
number["nbClub"] = recup["nbClub"];
number["nbVictoire"] = recup["nbVictoire"];
number["nbDefaite"] = recup["nbDefaite"];
}
};
xhr.open("GET","http://localhost:8080/load",true);
xhr.send();
}
Nodejs :
function load(response){
console.log("Load called");
fs.readFile("number.json", function(err,data){
if(err) {
throw err;
response.setHeader("Access-Control-Allow-Origin","*");
response.writeHead(418);
response.end();
}
else{
response.setHeader("Access-Control-Allow-Origin","*");
response.writeHead(200);
response.write(data);
response.end();
}
});
}