1

Im trying to accomplish SOAP-post to get back XML data.

Problem is that "No 'Access-Control-Allow-Origin' header" and I suppose that the server needs to add the header.

So I created a MockService in SOAPui and copied the server response. But I still get the same problem. In soapUI in the response I added this https://i.stack.imgur.com/fpkFG.jpg

        function soap() {
        var sr = MySoapRequest;

        $.ajax({  
       url: url, 
        beforeSend: function(xhr) {
        xhr.setRequestHeader("SOAPAction", "x");
        }, 
        type: "POST",  
        dataType: "xml",  
        data: sr, 
        crossDomain: true, 
        success: function (data) {
            console.log(data);
        },
        error: function (error) {
        },
        contentType: "text/xml; charset=\"utf-8\"" 
        });
            }
123456
  • 15
  • 1
  • 3

1 Answers1

-1

By default, browsers cannot make POST requests via AJAX to URLs which are not in the same origin as the current page. For example, if you have open a page that sits in the URL http://foo.com, and that page tries to post some data (via AJAX) to http://bar.com, you will normally get the error you are seeing now.

If you want to make this work, you have to configure your server to accept requests via Cross-Origin Resource Sharing (CORS). I suggest that you get some information about CORS, you can find a lot of documentation online about it. An extensive overview can be found here.

As for the actual implementation of CORS on your server, it depends on which platform you are using. If you are using PHP, have a look at this question.

Community
  • 1
  • 1
Stefano Dalpiaz
  • 1,673
  • 10
  • 11