Alex
Alex

Reputation: 163

Call Webservice with jQuery Ajax

i´m trying to call my webservice with jquery.ajax.

jQuery.support.cors = true;
    $.ajax({
        type: 'POST',
        url: wsUrl,
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        cache: false,
        crossDomain: true,
        data: soapRequest,
        success: reqSuccess,
        error: reqError
    });

I get "Access denied"-Error and status / readyState 0.

If i make a request to my webservice with SoapUI, it works very well.

Upvotes: 1

Views: 554

Answers (1)

doublesharp
doublesharp

Reputation: 27607

When making a SOAP request, make sure to set processData to false to prevent jQuery from converting your XML request to a string.

$.ajax({
    type: 'POST',
    url: wsUrl,
    contentType: "text/xml; charset=utf-8",
    dataType: "xml",
    cache: false,
    crossDomain: true,
    data: soapRequest,
    processData: false,
    success: reqSuccess,
    error: reqError
});

From the docs: http://api.jquery.com/jQuery.ajax/

processData (default: true)
Type: Boolean
By default, data passed in to the data option as an object (technically, anything 
other than a string) will be processed and transformed into a query string, fitting 
to the default content-type "application/x-www-form-urlencoded". If you want to send 
a DOMDocument, or other non-processed data, set this option to false.

Upvotes: 1

Related Questions