I am trying to read a json file (not on a server, just on a file in a folder on my desktop), using the jQuery method $.get(). Note that the html file and the json file are in the same file directory. For some reason, in the console of the web page, this error occurs:
Access to XMLHttpRequest at 'file:///Users/Harry/Desktop/HTML:CSS:Javascript.html/file.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
Here is my code:
<!DOCTYPE html>
<html>
<body>
<h1 id="header"></h1>
<script src="jQuery/jquery-3.4.1.js"></script>
<script>
$.getJSON("file.json", function (data) {
console.log("It worked!");
});
</script>
</body>
</html>
How to stop this error from being thrown?