I have a problem with get json data from file. I have an error 404 (Not found) in console. I dont know what is wrong, when i put url instead of a file path its works
export const loadProducts = {
init: function () {
this.getFromJson();
},
getFromJson: function() {
const request = new XMLHttpRequest();
request.open('GET', '../data/products.json', true);
request.onreadystatechange = function() {
if (request.status == 200){
console.log('data')
const files = JSON.parse(request.response);
}
else {
console.log('connected, but API returned an error');
}
};
request.onerror = function() {
console.log('connection error');
};
request.send();
}
}