Answer the question
In order to leave comments, you need to log in
How to fix "No 'Access-Control-Allow-Origin' header is present on the requested resource"?
I'm including js in an html page but getting the error "No 'Access-Control-Allow-Origin' header is present on the requested resource."
Here is the code:
function Parse (params, method) {
// Formating
var access_token = '25a545548xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var v = 5.78
var params = Object.extend({}, params, {
access_token,
v
})
var url = Format(params, method)
// Send request
$.ajax({
url,
dataType : "json",
headers: {'Access-Control-Allow-Origin': '*'},
success: function (data, textStatus) {
console.log(data)
}
})
}
Answer the question
In order to leave comments, you need to log in
it will not be possible to make requests to the VK API directly from the page script. Headers are expected from their server, and of course no one in VK will register your server address as allowed.
Use their js sdk.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question