【问题标题】:REST API - JSON data to HTML table using JQUERYREST API - 使用 JQUERY 将 JSON 数据转换为 HTML 表
【发布时间】:2019-05-01 00:01:06
【问题描述】:

我想通过 Jquery 将 API 中的数据显示到 HTML 表中,但它没有将数据显示到表中。我相信这是由于 JSON 结构 这是 HTML 文件

        <thead>
            <tr>
                <th>A</th>
                <th>B</th>
                <th>C</th>
            </tr>
        </thead>
        <tbody id="mydata">
            <tr>
                <td>[[E]]</td>
                <td>[[F]]</td>
                <td>[[G]]</td>
            </tr>           
        </tbody>
    </table>
    </div>

    <script>
        function UserAction() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
         if (this.readyState == 4 && this.status == 200) {
             alert(this.responseText);
         }
    };
    xhttp.open("GET", "https:xxxxxxx", true);
    xhttp.setRequestHeader("Content-type", "application/json");
    xhttp.setRequestHeader("Authorization", "Bearer eyJhbGciOiJIUzI1Nixxxxxxx");
}
    $("#mydata").mirandajs(xhhtp);
    </script>

关于 JSON 响应,我想获取 播放器、时间戳和原因,并将数据渲染到表格中(在示例中为 E、F、G)这里是 API 响应

{
    "meta": {
        "active": 2,
        "expired": 275,
        "total": 277
    },
    "links": {
        "next": "https://api.xxxxxxx"
    },
    "data": [
        {
            "type": "xxx",
            "id": "xxxx",
            "meta": {
                "player": "Serbo"
            },
            "attributes": {
                "id": "xxxx",
                "uid": "xxxx",
                "timestamp": "2018-07-11T13:02:14.663Z",
                "reason": "xxxxxxx",
                "note": null,
                "identifiers": [
                    {
                        "id": xxxxxxx,
                        "type": "xxxxxxx",
                        "identifier": "xxxxxxx",
                        "private": true,
                        "lastSeen": "2018-08-17T16:23:24.865+00:00"
                    }
                ]

请注意,我需要 json 对象内部的数据,然后是属性对象内部的数据

【问题讨论】:

  • 你有没有尝试过?
  • 我尝试使用 Ajax,因为这个小提琴显示 jsfiddle.net/pb1hxexL/6 但什么也没有:(

标签: json html rest api


【解决方案1】:

解决了,是关于我调用 API 的方式

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 2023-03-18
    • 2016-04-27
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多