0

I am facing 'Access to XMLHttpRequest at 'URL' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource' in javascript.

I have gone through many of the answers in the StackOverflow site. None of them worked for me. This request is to a remote server which I don't have control over it. I can only use the response from the site.

I have tried to add the

"headers": {

"Access-Control-Allow-Origin":"*"}

But this has changed nothing. I saw one option to add also.

dataType: "jsonp"

But dunno if these have any effects since I don't have any control over the response from the server.

This is what my request looks like.

$.ajax({
  type: "GET",
  dataType: "json",
  "headers": {
    "Access-Control-Allow-Origin":"*"
},
  url: URL,
  crossDomain: true,
  success: function(result) {
    console.log('success');
  },
  error: function(req, status, err) {
    console.log('Something went wrong', status, err);
  }
});

I read that we can access Only if the remote server supports JSONP or HTTP Access-Control headers.

If so what I can do in my case?

can anyone of you please help with this.

I have gone through the policy and checked some of the solutions.

http://anyorigin.com this is the only one that felt will work for me.But I am trying to access an internal domain.I felt It can introduce some security threat.

  • The header configuration must be done in your server application. Which is running in `http://localhost:8000` – Danizavtz May 12 '20 at 03:24
  • I have tested from both http and file ones. @Danizavtz – aswathy sali May 12 '20 at 04:39
  • @Danizavtz — That's the origin server, not the server the request is being made to. – Quentin May 12 '20 at 09:46
  • @Quentin I have already gone through the answers mentioned in the post you suggested. Those are not working for me since I don't have control over the other domain. it has some security risks as well since this is a private server URL. – aswathy sali May 12 '20 at 09:58
  • @aswathysali — The duplicate has a comprehensive answer. Those are your options. If you don't like them then you are out of luck. – Quentin May 12 '20 at 11:34

0 Answers0