发出HTTP请求时出现Access-Control-Allow-Origin错误

时间:2013-05-02 08:35:02

标签: javascript jquery html oauth-2.0 box-api

您好,我正在通过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,并添加了回调=?对于网址,但我尝试过的任何工作都没有。

2 个答案:

答案 0 :(得分:1)

http://developers.box.com/docs/

  

Box API支持CORS   逐个应用程序。如果您正在构建需要CORS的应用程序,   请联系我们,说明您的用例。

答案 1 :(得分:0)

另一种方法是使用YQL,因为常见问题解答中的开发人员会对其进行描述。

相关问题