尝试在html列表中推送xhr数据

时间:2018-02-08 16:32:50

标签: javascript endpoint trello

我正在尝试在html列表中循环并推送一个数组(由Trello Api检索)。我的xhr响应很好,但当我尝试循环并推入列表时,我没有数据......

如果我通过一个例子改变我的var nearTerm:

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

没关系......

我做错了什么?

        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; 

0 个答案:

没有答案