0
votes

I have an ASMX Web Service, which I can consume from jQuery $ajax: I can do it from Chrome, but not from Internet Explorer 11.

I read about CORS limitation and I disabled it on the service, by adding these lines to the web.config:

<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Methods" value="ACL, CANCELUPLOAD, CHECKIN, CHECKOUT, COPY, DELETE, GET, HEAD, LOCK, MKCALENDAR, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PROPPATCH, PUT, REPORT, SEARCH, UNCHECKOUT, UNLOCK, UPDATE, VERSION-CONTROL" />
<add name="Access-Control-Allow-Headers" value="Overwrite, Destination, Content-Type, Depth, User-Agent, Translate, Range, Content-Range, Timeout, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Location, Lock-Token, If" />
<add name="Access-Control-Expose-Headers" value="DAV, content-length, Allow" />
<add name="Access-Control-Max-Age" value="3600" />

Once the config is added, the cross-domain access started to work from Google Chrome, and I could get results from the web service. But Internet Explorer continues with the same problem (the process is going to the error part of the ajax call, and shows message "undefined")

Also checked the Internet Explorer option in Internet Tools > Security > Custom Level > Miscellaneous > Access data sources across domains > Enable

EDIT: This is the client javascript code:

    function GetSampleText() {
        $.ajax({
            url: 'http://MyWebServices/MyWebService.asmx/GetSampleText',
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: '{}',
            success: function (result) {
                $("#txtResult").val("OK: " + result.d);
            },
            error: function (request, status, error) {
                $("#txtResult").val("ERROR: " + request.responseText);
            }
            //error: function (result) {
            //    $("#txtResult").val("ERROR: " + result.d);
            //}
        }); 
    }

I could get a different message using:

error: function (request, status, error) {
    $("#txtResult").val("ERROR: " + request.responseText);
}

I'm getting: NO TRANSPORT

What I'm missing to make it work in Internet Explorer?

1
"shows message "undefined"" 👈 sounds like something is wrong here. What does your error handler look like? In fact, what does your entire AJAX code look like? – Phil
Yeah, that's not what the error handler signature looks like at all. Take a closer look at the documentation – Phil

1 Answers

0
votes

For those users who have the same problem, I could solve it by adding this line before all the ajax calls:

$.support.cors = true; // this must precede $.ajax({}) configuration

Regards,