Is there a way to access the API from the url without the need of the Chrome extension CORS (Allow-Control-Allow-Origin)? The code works only with the extension turned on. I have no access to the remote server.
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
callback(null, xhr.response);
} else {
callback(status);
}
};
xhr.send();
};
getJSON('http://faust.izor.hr/autodatapub/postaja_json_r?p_pos_id=4', function(err, data) {
if (err != null) {
console.error(err);
} else {
var text = data[1].Ime;
document.getElementById("id01").innerHTML = text;
console.log(text);
}
});
The error without the CORS plugin is: Access to XMLHttpRequest at 'http://faust.izor.hr/autodatapub/postaja_json_r?p_pos_id=4' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.