A
A
agromov912020-06-22 16:34:27
JavaScript
agromov91, 2020-06-22 16:34:27

Sending request to server, CORS errors?

There is such a code, it gives errors in the console:

Cause: CORS request failed
Reason: CORS header "Access-Control-Allow-Origin" is missing In

htaccess I tried to add Header set Access-Control-Allow-Origin: "*"
Did not help

what could be the matter?

let request = new XMLHttpRequest();

request.open('GET', 'https://currate.ru/api/?get=rates&pairs=USDRUB&key=910be200aa1e6b9b1c60917731de311c');
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
request.withCredentials = true;
request.send();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arseny, 2020-06-22
@agromov91

If the server is configured correctly, then you can pay attention to fetch, which in the request settings allows you to set the no-cors flag without too much headache.
https://developer.mozilla.org/ru/docs/Web/API/Fetc...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question