While delving into the world of AJAX, I encountered an issue when trying to fetch data from a local file. An error related to CORS popped up, despite my attempts to solve it by installing the 'allow-access-control-origin' plugin. Any assistance with this problem would be greatly appreciated.
Below is a snippet of my JavaScript code:
function loadData() {
const xhr = new XMLHttpRequest();
xhr.open('GET', '/data.txt', true);
xhr.onprogress = function(){
console.log('READYSTATE', xhr.readyState);
}
xhr.onload = function(){
console.log('READYSTATE', xhr.readyState);
if(this.status === 200) {
document.getElementById('output').innerHTML = `<h1>${this.responseText}</h1>`;
}
}
xhr.onerror = function() {
console.log('Request error...');
}
xhr.send();
}
The error output can be seen in this image: [link to error image][2]