3

I've got a jQuery SOAP request which for some reason does not work. What bothers me is that I've considered everything necessary for a CORS request, but all it returns is status 0 with the statusText "Error".

I know this is probably an unproductive (and dumb) question, but may you please take a look and find what I couldn't? I'd be really glad since this is exasperating me for days now. The code is a complete HTML file with JS already and can be taken as-is, only the jQuery path has to be adjusted.

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";
        jQuery.ajax({
            type: "POST",
            url: url,
            data: request,
            dataType: "xml",
            crossDomain: true,
            processData: 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"
            },
            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>

Analysing the response via Firebug, there's some weird error message in the XML part:

XML-Verarbeitungsfehler: Nicht übereinstimmendes Tag. Erwartet: </input>. Adresse: moz-nullprincipal:{e5ad2994-5e6d-4c61-9c47-7cad2f80f169} Zeile Nr. 71, Spalte 96:
...frmInput" type="text" size="50" name="Celsius"></td>
...-------------------------------------------------^

... which simply means "XML processing error: non-matching tag. Expected , line 71, column 96". Is that a serverside error? Because it cannot come from my minified HTML fiel as it does not have a table.

Kind regards, jaySon

jaySon
  • 795
  • 2
  • 7
  • 20
  • It looks like the response you get is from this page: http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit – Igal S. Nov 02 '14 at 13:43
  • It is and I am under the impression that this is how it's supposed to be in order to get a proper result. – jaySon Nov 02 '14 at 15:36
  • This is just their test page. Go there and type some number, and press 'Invoke' - you will get an XML response. xxx- So it looks to me that you invoke the wrong URL. You should invoke http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit instead. – Igal S. Nov 03 '14 at 09:05
  • Well, even with that URL it still gives me the same error: "Cross origin request blocked". – jaySon Nov 04 '14 at 15:37
  • Cross-domain requests require the server to set the proper CORS headers to work. If the w3schools API you're using does not provide CORS support, you cannot access the resource on your page via JavaScript without a server side proxy. – jonafato Nov 10 '14 at 02:45
  • possible duplicate of [Call WCF service from JQuery : cross-origin OPTIONS request gives error 400](http://stackoverflow.com/questions/18874320/call-wcf-service-from-jquery-cross-origin-options-request-gives-error-400) – Paul Sweatte May 05 '15 at 13:42

0 Answers0