I am still learning api calls, and currently receive an error regarding Cross Origin Resource Sharing - from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
to my vague understanding, this may be resolved by with "Http Response Header" Access-Control-Allow-Origin: http://example.com:8080
I am not quite sure how to do this.
with my current javascript being
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "https://otherexample.com/", true);
xhttp.setRequestHeader('Authorization','Basic Yhtghufhilahliviemiufhiaowi87975 ==');
xhttp.send();
}
would my new code be
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "https://otherexample.com/", true);
xhttp.setRequestHeader('Access-Control-Allow-Origin','http:example.com:8080')
xhttp.setRequestHeader('Authorization','Basic Yhtghufhilahliviemiufhiaowi87975 ==');
xhttp.send();
}
i have tried this but doesn't seem to work.