从json api获取数据,但不将其显示在html表中

时间:2019-05-27 20:55:00

标签: javascript html css datatables

我对如何从网站检索数据并将其显示为html感兴趣。然后我从一个网站上找到一个示例,并尝试更改其中的一些代码。但随后浏览器不会显示现有数据。这是一个例子:

</scrypt>
$(document).ready(function() {
        $('#example').DataTable({
            "processing": true,
            "ajax": "https://www.zpool.ca/api/miners",

            column: [{
                "algo"
            }, {
                "version"
            }, {
                "count"
    }]
  });
});</scrypt>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script src='https://code.jquery.com/jquery-3.3.1.js'/>
<script src='https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js'/>
    <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Algo</th>
                <th>Version</th>
                <th>Count</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Algo</th>
                <th>Version</th>
                <th>Count</th>
            </tr>
        </tfoot>
    </table>

有人可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

在发布问题之前,请先阅读文档,那里有一个确切的例子 https://datatables.net/examples/ajax/custom_data_flat.html

固定代码:

$(document).ready(function() {
    $('#example').DataTable( {
        "ajax": {
            "url": "https://www.zpool.ca/api/miners",
            "dataSrc": ""
        },
        "columns": [
            { "data": "algo" },
            { "data": "version" },
            { "data": "count" }
        ]
    } );
} );