document.querySelector("#btn").addEventListener("click",loadData);
function loadData(){
const xhr = new XMLHttpRequest();
console.log("READYSTAT",xhr.readyState)
xhr.open("GET","trial.txt", true)
xhr.onload = function(){
if(this.status === 200){
console.log(this.responseText)
}
}
This is the error
Access to XMLHttpRequest at 'file:///C:/Users/kenne/OneDrive/Desktop/javascript/trial.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
xhr.send();
}