Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryajax中的Post请求_Jquery_Ajax_Cors_Box Api - Fatal编程技术网

jqueryajax中的Post请求

jqueryajax中的Post请求,jquery,ajax,cors,box-api,Jquery,Ajax,Cors,Box Api,您好,我正在使用box api进行集成,他们刚刚给出了curl以获取访问令牌 具体如下 curl https://www.box.com/api/oauth2/token \ -d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \ -X POST 我想使用jquery ajax请求获取访问令牌,我

您好,我正在使用box api进行集成,他们刚刚给出了curl以获取访问令牌 具体如下

curl https://www.box.com/api/oauth2/token \
-d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \
-X POST
我想使用jquery ajax请求获取访问令牌,我的代码如下所示:

var data2= '{"grant_type":"authorization_code", "client_id":"READACTED" ,"client_secret":"Redacted" ,"code" :"'+code+'"}';
var data1 = JSON.parse(data2);

$.ajax({
                    type: 'POST',
                    url:  "https://www.box.com/api/oauth2/token",
                    data: data1,
                    success: function(json) {
                        console.log(e);
                       alert("success"+json);
                    },
                    error: function(e) {
                        console.log(e)
                        alert("Failure"+ JSON.stringify(e));

                    }
                });
我面临此请求的问题,因为它在浏览器控制台中给了我错误:

XMLHttpRequest cannot load https://www.box.com/api/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

请告诉我哪里我错了它与邮递员客户的工作正常。

为了通过相同来源的政策,您需要联系Box支持团队。你可以通过电子邮件api@box.com或者点击右下角盒子网页上的“盒子社区”链接


支持团队将要求您在CORS标题中输入要使用的一个或多个源URL(框不允许通配符源)。他们还需要知道您的应用程序名称或API密钥,以便查找您的应用程序并为您设置CORS头

你想干什么?你尝试了什么?@RocketHazmat请检查,现在我已经提到了更多的细节,你正在被网络阻止。您不能直接从JavaScript访问box.com API。我现在该怎么办>您需要在服务器上创建一个脚本来联系API,然后让AJAX调用指向该API。