I'm disperate looking for a solution to cors issue. I have the following script in my html page
var webserUrl = "http://www.webservicex.com/globalweather.asmx";
var soapRequest =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET"> '+
' <soapenv:Header/> '+
' <soapenv:Body> '+
' <web:GetCitiesByCountry> '+
' <!--Optional:--> '+
' <web:CountryName>SPAIN</web:CountryName> '+
' </web:GetCitiesByCountry> '+
' </soapenv:Body> '+
'</soapenv:Envelope> ';
var req = new XMLHttpRequest();
req.open("POST", webserUrl);
req.setRequestHeader("Content-Type","text/xml");
req.setRequestHeader("Access-Control-Allow-Origin","*");
req.send(soapRequest);
req.addEventListener("readystatechange",function()
{
console.log(req);
alert(req.status);
if (req.readyState === 4 )
{
alert(req.statusText);
}
else {
alert(req.readyState);
}
},false);
This is a free public web service, when I execute this on the browser (chrome) I obtain (looking for errors F12)
Failed to load resource: the server responded with a status of 404 (Not Found) jbondNi:1 Failed to load http://www.webservicex.com/globalweather.asmx: 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:51131' is therefore not allowed access.
Please help how to solve this issue. Thank you