Hi
Apologies if there is already a thread on this topic. I have searched the group but not found anything that matches.
I have some JavaScript in my html page which uses XMLHttpRequest();
Today I learned about CORS which seems to be blocking me as I receive the following error in Chrome:
"XMLHttpRequest cannot load
https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb7.asmx. 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."
This is what I am trying to do but can't get any further.
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript">
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', '
https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb7.asmx', true);
// build SOAP request
var sr =
'<soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="
http://thalesgroup.com/RTTI/2013-11-28/Token/types" xmlns:ldb="
http://thalesgroup.com/RTTI/2015-05-14/ldb/">' +
' <soapenv:Header>' +
' <typ:AccessToken>' +
' <typ:TokenValue>my_token_removed</typ:TokenValue>' +
' </typ:AccessToken>' +
' </soapenv:Header>' +
' <soapenv:Body>' +
' <ldb:GetDepartureBoardRequest>' +
' <ldb:numRows>10</ldb:numRows>' +
' <ldb:crs>HYR</ldb:crs>' +
' </ldb:GetDepartureBoardRequest>' +
' </soapenv:Body>' +
'</soapenv:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert('Done. Check Console');
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...
}
</script>
</head>
<body>
<form name="Demo" action="" method="post">
<div>
<input type="button" value="Soap" onclick="soap();" />
</div>
</form>
</body>
<html>
Is anyone else trying to do something similar? Maybe with the same results, or even better - a resolution?
Any advice is much appreciated.
Thank you.