简体   繁体   English

未使用jQuery的Datatables插件从Ajax调用中填充表

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

The ajax request is returning the following data ajax请求返回以下数据

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

The HTML is: 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>

And the javascript is 而JavaScript是

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

Any idea why the table is not being filled 不知道为什么表格没有被填充

Just looking at their docs , I believe your json has to be formatted as so. 只看他们的文档 ,我相信您的json必须被格式化。

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

Javascript error JavaScript错误

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

Sorted it all columns now bind 排序后,所有列现在绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM