My goal is to regularly load a .json file containing some information, and here is the code I have come up with:
var updateIBEX35 = function () {
var ibexText = document.getElementById("IBEX");
let url = 'https://www2.ecobolsa.com/js/data/i35.json';
fetch(url).then(res => res.json()).then((out) => {
alert(out[0].p); // for debugging purposes
}) .catch(err => alert(err));
}
var intervalID = setInterval(updateIBEX35, 1000);
// clearInterval(intervalID);
However, I encountered an error which states:
[Error] Origin http://localhost is not allowed by Access-Control-Allow-Origin.
[Error] Failed to load resource: Origin http://localhost is not allowed by Access-Control-Allow-Origin. (i35.json, line 0)
[Error] Fetch API cannot load https://www2.ecobolsa.com/js/data/i35.json. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
By the way, I am using macOS Sierra with Apache, and I attempted to modify the "httpd.conf" or the user file (/etc/apache2/users/Daniel.conf) by adding the following:
Header set Access-Control-Allow-Origin "*"
Unfortunately, the solution did not work as expected :(