Javascript CORS - No hay encabezado 'Access-Control-Allow-Origin' está presente
He estado trabajando con CORS y encontré el siguiente problema. El cliente se queja de que no hay encabezado 'Access-Control-Allow-Origin', mientras queestan presentesyel cliente realiza la solicitud POST real yrecibe 200.
function initializeXMLHttpRequest(url) { //the code that initialize the xhr
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.withCredentials = true;
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
//set headers
for (var key in headers) {
if (headers.hasOwnProperty(key)) { //filter out inherited properties
xhr.setRequestHeader(key,headers[key]);
}
}
return xhr;
}
En cromo
registro de la consola de Chrome
Solicitud de OPCIONES de Chrome
En Firefox
Registro de la consola de Firefox