0

I'm trying to loop and push an array (retrieve by Trello Api) in a html list. I'm getting well the xhr response, but when I try to loop and push in my list, I have no datas...

If I change my var nearTerm by an example :

[{"id":"1","name":"Item 1"},{"id":"2","name":"Item 2"},{"id":"3","name":"Item 3"}]

It's ok...

What I'm doing wrong ?

        var apiUrl         = "https://api.trello.com/1/lists/";
        var apiKey         = "myKey";
        var apiTok         = "myToken";
        var nearTermListId = "MyListId";

        function getCardsByStatus(status) {
            var data = null;

            var xhr = new XMLHttpRequest();

            xhr.onreadystatechange = function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            };

            xhr.open("GET", apiUrl + status +"/cards?fields=name&key="+ apiKey +"&token="+ apiTok +"", true);

            xhr.send(data);
        }

        var nearTerm = getCardsByStatus(nearTermListId)

        var list, name, x = [];
        list = nearTerm;

        for (name in list) {
            x += "<li>" + list[name].name + "</li>";
        }

        document.getElementById("wip").innerHTML = x; 
christophebazin
  • 200
  • 2
  • 4
  • 14

0 Answers0