jQuery AJAX CORS request does not work in Safari, Chrome in OS X

997 Views Asked by At

Created a simple jQuery Ajax code which make a CORS request to the Server which servers the REST API. Applied CORS filter in server and applied necessary changes in the filter mapping for Access-Control-Allow-Origin, Access-Control-Allow-Headers, Access-Control-Allow-Methods, Access-Control-Allow-Credentials, etc.

The jQuery ajax call works fine in Chrome, Safari, IE in Windows OS and also it's working in iOS devices. But the same code does not work in Safari, Chrome of OS X. When I run the script file, first it makes a preflight OPTION request, but the OPTION request fails saying ERR_NO_RESPONSE. But I could not see any response headers in that OPTION request. Verified in wireshark that no request has been made to the server during OPTION request. Then verified in curl command (i.e. curl -X OPTIONS http://myserverdomain.com). The command is success and am getting the response.

Not able to get why it does not work in browser of OS X. Verifies the browser settings, checked firewall, disabled web security but the same issue persists.

Below is the jQuery ajax code which I am using:

$.ajaxSetup({
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            crossDomain: true,           
            async:true,
            xhrFields:{ 
                withCredentials:true 
            },
            timeout:60000
    });
    $.ajax({
            url: "http://myserverdomain.com",
            type: "POST",
            data:jsonData
            })
            .done(function(data) {
                console.log(data);              
                })
            .fail(function(textStatus) {                
                console.log(textStatus);
                });
    }        
1

There are 1 best solutions below

0
On BEST ANSWER

This issue is solved by uninstalling the web security in Cisco Anyconnect VPN Client with the command (sudo /opt/cisco/anyconnect/bin/websecurity_uninstall.sh) . because that was blocking the CORS ajax request to the server. After removing the websecurity everything seems working fine