0

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>
jaySon
  • 795
  • 2
  • 7
  • 20
  • `crossDomain` doesn't do what you think it does. jQuery doesn't add extra headers when making a cross origin request because they make it a complex request (which requires a preflight options check). `crossDomain` is used to apply the same settings to a *same* origin request so that you can redirect to a different origin and still not trigger a complex request. – Quentin Nov 04 '14 at 17:15
  • Well, OK, I didn't read it that way, so thanks. But that only answers the "less interesting" part of my question, neither does the one you marked as original to this one here. The problem is that all responses dealing with handling CORS requests deal with server side stuff, but I don't have access to the server, plus the server is ment to be a "SOAP test server", so I consider the serverside settings as correct. I'm sorry, it's just too "encrypted" to me. I could really need some guidence. – jaySon Nov 04 '14 at 17:31
  • Not all the answers on the duplicate use CORS as the solution. There is no way to do SOAP cross-domain, directly from the browser without the server giving the site the request is coming from permission. – Quentin Nov 04 '14 at 19:44

0 Answers0