Search code examples
javascriptjsontrello

GET Trello JSON to put in a string var


I'm trying to get the JSON that a TRELLO API Url returns and put it into a string. On my own private board I am getting "401 Unauthorized". But the Trello Api doesn't seem to give any way to authorize a user through the URL. If I try a public board I get "XMLHttpRequest cannot load https://api.trello.com/1/board/4d5ea62fd76aa1136000000c?key=68d02bf40d2ad57dd9eb418eb15f9564. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers."

This is my code:

     <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>

Solution

  • Try to use this JSONP call which is allowed to be cross-domain.

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

    DEMO

    See: http://api.jquery.com/jQuery.getJSON/#jsonp