I'm attempting to do an API post but I get the following error, 405 (Method Not Allowed) Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1' is therefore not allowed access.
this is my code:
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "url + parameters");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Basic: username:pasword");
xhr.setRequestHeader("Accept", "application/json, text/plain, */*'");
xhr.setRequestHeader("Access-Control-Allow-Origin", "Http://127.0.0.1");
xhr.setRequestHeader("Access-Control-Allow-Headers", "Content-Type");
xhr.setRequestHeader("Access-Control-Allow-Methods", "POST,GET");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.send(data);
Please if anyone could assist. Thank you