【发布时间】:2013-04-26 08:43:49
【问题描述】:
您好,我正在通过 OAuth 2.0 对用户进行身份验证,并且在发出以下 POST 请求时遇到 Access-Control-Allow-Origin 错误 (XMLHttpRequest cannot load https://www.box.com/api/oauth2/token. Origin http://localhost is not allowed by Access-Control-Allow-Origin.):
var xhr=new XMLHttpRequest();
xhr.open('POST',path,true);
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.onload = function() {
var text = xhr.responseText;
alert('Response from request to ' + path + ': ' + text);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.send(params);
任何帮助将不胜感激!我研究了 CORS、JSONP 并添加了 callback=?到网址,但我尝试过的没有任何效果。
【问题讨论】:
标签: javascript jquery html oauth-2.0 box-api