D
D
Dmitry2021-11-03 12:48:05
CORS
Dmitry, 2021-11-03 12:48:05

Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type application/json How to solve?

Good day.
I ran into a problem when sending a request to the Vkontakte API. I searched for a solution to the problem, but did not find it.
I realized that you can’t send a request from one domain to another just like that, but I didn’t understand how to solve it.
Used 2 ways to connect.
Method number 1:

<script type="text/javascript">
            var script = document.createElement('SCRIPT');
            script.src = "https://api.vk.com/method/board.getComments?&group_id=54767201&topic_id=38534787&access_token=bb33ea88418164920d56079a8d50bacef683fcc323327336b3deb89a4ce77267cfaa0e792acb8dcbe15d1&v=5.131";
            document.getElementsByTagName("head")[0].appendChild(script);

            function callbackFunc(result) {
                console.log(result.response);
            }
            console.log(response);
        </script>

Just this one gives the error Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type application/json
And the second way:
<script type="text/javascript">
            let xhr = new XMLHttpRequest();
            xhr.open('GET', 'https://api.vk.com/method/board.getComments?&group_id=54767201&topic_id=38534787&access_token=bb33ea88418164920d56079a8d50bacef683fcc323327336b3deb89a4ce77267cfaa0e792acb8dcbe15d1&v=5.131', true);
            xhr.onload = function() {
                if (xhr.status === 200) {
                    let data = JSON.parse(xhr.responseText);
                    console.log(data);
                } else {
                    alert(xhr.status);
                }
            };
            xhr.send();
            console.log(1)
        </script>

Here I get the following error:
Access to XMLHttpRequest at MY-API from origin 'MY-SITE' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2021-11-03
@zkrvndm

You need to proxy the request through your server (website). What is your website running on? In PHP?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question