I've create a very simple SOAP request to access an example web service hosted by W3Schools (Code below). Now, executing the script (by pressing the button), the response is an OPTIONS with code 200 OK.
So the service is seemingly up, I've got "crossDomain" enabled in my ajax request, yet it won't post the actual data. How do I fix this? I've done days of research and still couldn't get an answer I could use for JavaScript. Please help!
Kind regards, jaySon
<html>
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript" src="jquery-2.1.1.min.js" ></script>
<script type="text/javascript" >
function fnc_soap() {
var request =
'<?xml version="1.0" encoding="utf-8"?> ' +
'<soap12:Envelope ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" ' +
'soap12:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> ' +
'<soap12:Body> ' +
'<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/"> ' +
'<Celsius>37</Celsius> ' +
'</CelsiusToFahrenheit> ' +
'</soap12:Body> ' +
'</soap12:Envelope>';
var url = "http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit";
// var url = "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit";
jQuery.ajax({
type: "POST",
url: url,
data: request,
dataType: "xml",
crossDomain: true,
// contentType: "text/xml; charset=\"utf-8\"",
xhrFields: {
withCredentials: true
},
beforeSend: function(xhr) {
// xhr.setRequestHeader('Access-Control-Allow-Methods', 'OPTIONS, TRACE, GET, HEAD, POST');
xhr.withCredentials = true;
},
headers:
{
SOAPAction: "http://www.w3schools.com/webservices/CelsiusToFahrenheit",
// SOAPAction: "http://www.w3schools.com/webservices/tempconvert.asmx?CelsiusToFahrenheit"
"X-Requested-With": "XMLHttpRequest"
},
success: function (msg) {
alert("Works!");
},
error: function (msg) {
alert("Failed: " + msg.status + ": " + msg.statusText);
}
});
}
</script>
</head>
<body>
<form name="Demo" action="" method="post">
<div>
<input type="button" value="Soap" onclick="fnc_soap();" ></input>
</div>
</form>
</body>
<html>