M
M
Mitya ToDaSyo2019-05-29 16:42:17
JavaScript
Mitya ToDaSyo, 2019-05-29 16:42:17

How to overcome Access to XMLHttpRequest ... has been blocked by CORS policy?

I'm trying to send a request to another domain via XMLHttpRequest, but I keep getting the has been blocked error .
Both sides indicated:

<meta name="Access-Control-Allow-Headers" content="*" /> 
<meta name="Access-Control-Allow-Origin" content="*" />

Tried like this:
var xhr = new XMLHttpRequest();
xhr.open("GET", URL, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.send();

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>

What else can you try?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bespechnost, 2019-05-29
@dimastik1986

`Access-Control-Allow-Origin` is the response header from the server. If you have Nginx, the office will help you. documentation https://enable-cors.org/server_nginx.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question