1

ERROR:- Access to XMLHttpRequest at 'file:///F:/js/ajax/name.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https. script.js:16

//script.js

function loadDoc() {
var xhttp;
if (window.XMLHttpRequest) {
  // code for modern browsers
  xhttp = new XMLHttpRequest();
} else {
  // code for IE6, IE5
  xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    document.getElementById("demo").innerHTML = this.responseText;
  }
};
xhttp.open("GET", "name.txt", true);
xhttp.send();

}

  • 1
    The answer is in your question. – JavaScript Mar 13 '21 at 08:40
  • Does this answer your question? [XMLHttpRequest issue: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https](https://stackoverflow.com/questions/60786555/xmlhttprequest-issue-cross-origin-requests-are-only-supported-for-protocol-sche) – Sebastian Simon Mar 16 '21 at 11:03

1 Answers1

0

It worked for me!

  1. First of all Go to the extension and download Live Server.
  2. Press F1 and enter Live Server and choose Open with Live Server from menu and there you go :)
Aasha Pun
  • 1
  • 3