0

I'm just trying to open a static text file in the same parent folder as the JS script. This is the code I have tried:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    console.log(this.readyState)
    console.log(this.status)
};
xhttp.open("GET", "Files/English.txt", true);
xhttp.send();

But everytime the output is 1 0 4 0

The file structure is

container
    main.html
    Files
        English.txt
    JS
        test.js

I'm trying to load the English.txt file but the status is always 0 and in the console on the browser it says

Access to XMLHttpRequest at 'file:///M:/VSC/container/Files/English.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, brave, chrome-untrusted, https.

4

0

test.js:43 GET file:///M:/VSC/container/Files/English.txt net::ERR_FAILED

I just want to open this static (but long) text file in javascript so I can create some HTML elements but I can't even do that?

I am using brave browser.

tukars
  • 58
  • 6

0 Answers0