表没有被填充从Ajax调用使用数据表插件的jQuery

Table not being filled from Ajax Call using Datatables plug-in for jQuery

本文关键字:数据表 插件 jQuery 调用 Ajax 填充      更新时间:2023-09-26

ajax请求返回以下数据

    [{"ID":40,"Date":"'/Date(1407999600000)'/"},{"ID":39,"Date":"'/Date(1409036400000)'/"}

HTML是:

<table id="bookings-table" class="display">
<thead>
    <tr>
        <th>ID</th>
        <th>Date</th>
    </tr>
</thead>
<tfoot>
    <tr>
        <th>ID</th>
        <th>Date</th>
    </tr>
</tfoot>
</table>

javascript是

$(document).ready(function () {
    $('#bookings-table').dataTable({
        "ajaxSource": "/manager/Booking/GetBookings",
        "columns": [
        { "data": "ID" },
        { "data": "Date" }
        ]
    });
});

知道为什么表没有被填充吗

看看他们的文档,我相信你的json必须这样格式化。

{
    "data": [
        {
            "ID": 40,
            "Date": "'/Date(1407999600000)'/"
        },
        {
            "ID": 39,
            "Date": "'/Date(1409036400000)'/"
        }
    ]
}

Javascript错误

    $('#bookings-table').dataTable({
        "ajax": {
            "url": "/manager/Booking/GetBookings",
            "dataSrc": ""
        },

已排序的所有列现在绑定