javascript - GET Trello JSON 放入字符串变量

标签 javascript json trello

我正在尝试获取 TRELLO API Url 返回的 JSON 并将其放入字符串中。在我自己的私有(private)董事会上,我收到“401 Unauthorized”。但是 Trello Api 似乎没有提供任何方式来通过 URL 授权用户。如果我尝试使用公共(public)板,我会收到“XMLHttpRequest 无法加载 https://api.trello.com/1/board/4d5ea62fd76aa1136000000c?key=68d02bf40d2ad57dd9eb418eb15f9564。Access-Control-Allow-Headers 不允许请求 header 字段 X-Requested-With。”

这是我的代码:

     <body>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">  </script>

      <script>

      var list = $.getJSON(" https://api.trello.com/1/board/4d5ea62fd76aa1136000000c? key=68d02bf40d2ad57dd9eb418eb15f9564");
      document.getElementById('print').innerHTML = list;


      </script>
      <div id="print">
      </div>
      </body>

最佳答案

尝试使用这个JSONP允许跨域调用。

$.getJSON("https://api.trello.com/1/board/4d5ea62fd76aa1136000000c?&callback=?", {
    key: '68d02bf40d2ad57dd9eb418eb15f9564'
})
.success(function(responseObj) {
    document.getElementById('print').innerHTML = JSON.stringify(responseObj);
});

DEMO

参见:http://api.jquery.com/jQuery.getJSON/#jsonp

关于javascript - GET Trello JSON 放入字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12547825/

相关文章:

javascript - map 上所有标记的事件处理程序 - Google map V3

javascript - Angular 2 事件处理和自定义事件

javascript - 重命名没有 id 的按钮文本

java - 如何将 thrift 对象转换为可读字符串并将其转换回来?

javascript - 如何循环等待多个WebWorker

javascript - 递归解析JSON

java - Gson、JSON 和 LinkedTreeMap 的精妙之处

trello API 是所有对象中唯一的 id 值

javascript - 在 Trello Power-Up 中使用卡片数据