Отправка GET запроса на сервер с получением данных

Всем привет!

Необходимо отправить GET запрос на сервера ВКонтакте, по следующему url:

https://api.vk.com/method/users.get?user_id=210700286&v=5.52&access_token=TOKEN

В гугле нашёл такой способ:

var request = new XMLHttpRequest();
request.open('GET', 'https://api.vk.com/method/users.get?user_id=210700286&v=5.52&access_token=TOKEN',false);
request.onload = function() {
    alert(request.responseText);
}

request.send();

Выдаёт ошибку:

networkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load

Может кто знает альтернативные способы как это можно сделать в JS?

Попробовал через Fetch отправить GET запрос:

fetch('https://api.vk.com/method/users.get?user_id=210700286&v=5.52&access_token=TOKEN')
  .then((response) => {
  return response.json();
})

С Fetch ошибка такая:

1.Access to fetch at **URL**
from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
2.  GET **url** net::ERR_FAILED
3. Uncaught (in promise) TypeError: Failed to fetch

введите сюда описание изображения


Ответы (1 шт):

Автор решения: h4cktivist

Попробуйте отправить запрос через обычный fetch - документация

fetch('https://api.vk.com/method/users.get?user_id=210700286&v=5.52&access_token=TOKEN')
  .then((response) => {
  return response.json();
})
→ Ссылка