I am getting this error when trying to call a REST api from Javascript using XMLHttpRequest object. The code is inside a html file on my local disk.
Failed to load https://<>: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Referred to this link and tried setting the header Access-Control-Allow-Origin but still getting the same error.
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "https://<<url>>", false);
xhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
xhttp.setRequestHeader('Content-type', 'application/json');
xhttp.setRequestHeader('Authorization', 'Basic ' + btoa(username + ':' + password));
xhttp.send();