I am currently facing an issue with retrieving a file from the server where my PHP code is hosted, which is a web hosting service.
This problem is not unfamiliar to me as I have previously encountered difficulties accessing files from HTML, whether locally or from a server. Here is the code I am using:
<! DOCTYPE html >
<html>
<head>
<title>retrieve_activities_json.html</title>
</head>
<body>
<p id="demo"></p>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if( this.readystate == 4 && this.status == 200 ) {
var activities_obj = JSON.parse(this.responseText);
document.getElementById('demo').innerHTML = activities_obj[0];
}
};
xmlhttp.open("GET","activities.json", true);
xmlhttp.send();
</script>
</body>
</html>
I am wondering if there are any specific configurations on my browser or the web hosting server that can help me resolve the following error message:
Access to XMLHttpRequest at 'file:///D:/Web%20Development%20Tutorials/JavaScript%20Practice/activities.json' 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.