I am trying to load data from JSON to my website. Everything worked correctly for some time, but tonight I suddenly I started receiving the following error. (it works on localhost so far)
Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at FileReader.<anonymous>
Javascript calling the JSON is following:
function readJSON(path) {
var xhr = new XMLHttpRequest();
xhr.open('GET', path, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
var file = new File([this.response], 'temp');
var fileReader = new FileReader();
fileReader.addEventListener('load', function(){
// do stuff with fileReader.result
var volant = JSON.parse(fileReader.result);
// console.log(volant);
});
fileReader.readAsText(file);
}
}
xhr.send();
}
readJSON('https://volant.inexsda.cz/v1/workcamps.json');
I need to read data from the JSON, but now I cannot anymore. Can someone help please?
EDIT: Everything works correctly on Safari. The issue is happening in Chrome.
console.log(fileReader.result). Post that result and check it yourself for correctness.