Answer the question
In order to leave comments, you need to log in
VK blocks fetch 'GET' request. How to decide?
I need to get json response from vkontakte. There is a special API.
Here is the link: ' https://api.vk.com/method/friends.getSuggestions?f... '+$filter+'&fields='+$fields+'&count=500&access_token='+$token+'&v=5.103'
But using the fetch and xhr methods, VKontakte blocks the request with the following response: "Access to XMLHttpRequest at ' https://api.vk.com/method/friends.getSuggestions?f... ' from origin ' vk ' has been blocked by CORS policy : No 'Access-Control-Allow-Origin' header is present on the requested resource."
How to decide? In php it is solved very simply, with the following request: json_decode(file_get_contents(' https://api.vk.com/method/friends.getSuggestions?f...'.$filter.'&fields='.$fields.'&count=500&access_token='.$token.'&v=5.103'));
Here is the code with an error in JavaScript:
And here is with php, where there is no error:
Answer the question
In order to leave comments, you need to log in
Thanks everyone, issue resolved. Solved the issue with jquery.
With this code:
$.ajax({
url: ' https://api.vk.com/method/friends.getSuggestions?f... '+$filter+'&fields='+$fields+'&count=500&access_token='+ $token+'&v=5.103',
type: 'GET',
dataType: 'jsonp',
crossDomain: true,
success: function(data){
console.log(data.response);
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question