weixin_33690963 2013-12-17 11:26 采纳率: 0%
浏览 69

带有jquery ajax的POST请求

llo i am using box api to for integration they have given just curl to get access token which is as follow

is 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

I want to get access token using jquery ajax request i have tired my code like this as follow :

var data2= '{"grant_type":"authorization_code", "client_id":"61oliuyi1jckqos0j8zzl9h4t791umux" ,"client_secret":"Oi1XS56al61oOrrvAL3i5gdPTfe7QO9V" ,"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));

                    }
                });

MLHttpRequest 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.
  • 写回答

2条回答 默认 最新

  • weixin_33694172 2013-12-17 11:30
    关注

    The problem is simply due to cross-domain request. The Javascript Origin Policy is going to prevent you from making Ajax request to the API from another domain (like localhost, which you are using). Nice explanation of the error here.

    As you are trying to use Box.com API, you should use YQL to make your code working. This dev article from their blog shows exactly how to integrate YQL, and seems to be the best option.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?