how to fix WebService Post refuse

0

When Posting:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "/CmisWebRequests.asmx/GetMessageResponse",
    data: dataToSend,
    dataType: "json",
    async: true,
    error: function(ex) {
        alert("EXCEPTION: " + JSON.stringify(ex));
    },
    success: function(resp) {
        var messageResponse = resp.d;
        $("#response").text(JSON.stringify(resp));
        $("#success").text(messageResponse.Success);
        $("#responseText").text(messageResponse.Response);
    },
    complete: function() {

    }
})

I can not deny

  

Response to preflight request does not pass access control check: No   'Access-Control-Allow-Origin' header is present on the requested   resource

How to cede this permission to a particular requester?

    
asked by anonymous 08.03.2017 / 21:51

2 answers

1

This is an existing Web Browser protection that blocks JavaScript requests (AJAX) that are not made from the same source as your site.

This will happen if you are running a local JavaScript and connecting to an external API (another site), if the called server is on a different port, if the host is different among other restrictions.

The solution is for the server to send a header

Access-Control-Allow-Origin: *

To allow requests to be made from other sources.

If you can not change the server (solution) you can try the following:

  • Use a proxy, which sends the header above, because there you request the proxy and the proxy requests the API

  • Manually remove CORS lock from your browser (you can do this in Developer mode)

  • Use Internet Explorer or Chrome because Firefox is the most rigid in CORS

  • You can also use JSONP, but it depends on the support you have on the server (back to the source)

    Good luck

        
    08.03.2017 / 23:46
    0

    In IIS the solution was to access the Request Filtering MENU and assign the POST verb in the HTTP Verbs tab.

        
    09.03.2017 / 15:37