Here are a few unique strategies you can implement to resolve the issue:
1st approach: Instead of disabling security in the Chrome browser [not recommended], follow these steps:
- Close your Chrome browser.
Open your Terminal and enter the following command:
alias chrome="open /Applications/Google\ Chrome.app/ --args --disable-web-security"
Restart your Chrome browser. If the security is disabled successfully, you will see a yellow warning bar at the top of the Chrome window.
2nd Approach: Modify the dataType parameter to dataType:'jsonp'
like this:
$.ajax({
url: 'your domain url',
data: myData,
type: 'GET',
crossDomain: true,
dataType: 'jsonp',
success: function() { alert("Success"); },
error: function() { alert('Failed!'); },
beforeSend: setHeader
});
3rd Method: On the server-side, include the necessary headers keys/values
in the options method response like so:
void handleRequest(Request request, Response response) {
if(request.method == "OPTIONS") {
response.setHeader("Access-Control-Allow- Origin","Your_Domain")
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Content-Type");
}
}
4th Resolution: If using setHeader
does not work, attempt using addHeader
instead :
Utilize addHeader
-->
response.addHeader("Access-Control-Allow-Origin", "*");