Response to preflight request doesn’t pass access control check

Asked

Viewed 17,867 times

1

When I try to give a GET on a link here on my server that is not in host location happens this message:

Xmlhttprequest cannot load http://192.168.25.66:8089/datasnap/Rest/Tserverconnmonitormethods/Get_datahora. Response to preflight request doesn’t pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost' is therefore not allowed access. The Response had HTTP status code 500.

Code of the Request:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://192.168.25.66:8089/datasnap/rest/TServerConnMonitorMethods/Get_DataHora",
  "method": "GET",
  "headers": {
    "cache-control": "no-cache",
    "postman-token": "266b68dc-31a5-bf40-69f4-2fa3be60cd9c"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

1 answer

6


Web browsers have a security restriction, called Same Origin Policy. It makes certain requests, such as those made via Ajax, only allowed within the same domain.

The recommended solution is to use CORS (Cross-Origin Resource Sharing).

On the server add the header Access-Control-Allow-Origin, indicating which other domains (origins) are allowed to access that service.

Example:

Access-Control-Allow-Origin: http://www.seusite.com

Browser other questions tagged

You are not signed in. Login or sign up in order to post.