I have the website with analytics of main site index. Earlier I had it in PHP on https://www.status.webcoder.sk but now I'm trying to do it in nodejs on https://www.webcoderstatus.herokuapp.com but I have 1 problem.
Get data from text file from url is working with no problems with php but when I'm trying to do it with JavaScript there is problem with CORS policy.
My code is:
function getText(){
var request = new XMLHttpRequest();
request.open('GET', 'https://www.webcoder.sk/config/devices.txt', true);
request.send(null);
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
var type = request.getResponseHeader('Content-Type');
if (type.indexOf("text") !== 1) {
return request.responseText;
}
}
}
}
$(document).ready(function() {
var devices = getText();
console.log(devices);
});
This is the error message: (index):1 Access to XMLHttpRequest at 'https://www.webcoder.sk/config/devices.txt' from origin 'https://webcoderstatus.herokuapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.