I
I
Ivan Grishov2022-03-08 20:32:42
JavaScript
Ivan Grishov, 2022-03-08 20:32:42

Why is there an error due to a CORS request?

Good evening. I have my own website. In it, I created a db.json file and I want to access it from another project using axios, but an error appears:

Access to XMLHttpRequest at ' https://grishov.ru/db.json ' from origin ' localhost:8080 ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Having figured it out, I added a .htaccess file to the site and in it Header set Access-Control-Allow-Origin "*", but still the error does not disappear, I can not understand why.
Thanks for any advice.

622793671a6a2159106981.jpeg
622793382e88a833532719.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kot2566, 2022-03-08
@IvanGrishov

Crutch via https://cors-anywhere.herokuapp.com/https://grisho...
https://qna.habr.com/q/654661

$.ajax({
        type: "GET",
        url: 'https://cors-anywhere.herokuapp.com/https://grishov.ru/db.json',

        success: function (response) {
           console.log(response)
        }
    });

62279e26ccef9650709624.png

N
Nadim Zakirov, 2022-03-09
@zkrvndm

Having figured it out, I added a .htaccess file to the site and in it Header set Access-Control-Allow-Origin "*", but still the error does not disappear, I can not understand why.

Because you have this heading is NOT affixed. Your .htaccess file didn't work, look at the response headers:
622834397e4b7096207073.png
I don't see the Access-Control-Allow-Origin header there, that's the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question