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

0 Answers0