我看到一些有关此问题和答案,但不明白该怎么做。 我得到这个错误: XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 400.
XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 400.
XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 400.
正如我以前的帖子看到的,这是因为我不能让一个HTTP POST请求到另一台服务器。 我看到一些东西将JSONP,但不明白为什么。这是我用来发送请求的功能:
var url = 'https://accounts.google.com/o/oauth2/token';
var payload = {
grant_type: 'authorization_code',
code: authResult['code'],
client_id: clientID,
client_secret: clientSecret,
redirect_uri: '',
dataType: 'jsonp'
};
$.post(url, {
form: payload
}, function(error, response, body) {
console.log(body);
});