【问题标题】:DataTables warning: table id=bootstrap-data-table - Invalid JSON response - DataTables JS PluginDataTables 警告:table id=bootstrap-data-table - 无效的 JSON 响应 - DataTables JS 插件
【发布时间】:2018-12-10 11:20:57
【问题描述】:

我在 Web 窗体应用程序中使用 WebMethod 时遇到以下错误:

DataTables 警告:表 id=bootstrap-data-table - JSON 无效 回复。有关此错误的更多信息,请参阅 http://datatables.net/tn/1

当尝试在 DataTables 表中显示我的数据时,在我的 Jquery 代码中单击按钮时会发生这种情况。谁能告诉我我错过了什么?

jQuery:

document.getElementById("openReqMenuButton").onclick = function () {
            jQuery(document).ready(function () {
                jQuery('#bootstrap-data-table').DataTable({
                    "processing": true,
                    "serverSide": true,
                    'searching': true,
                    'sort': true,
                    "ajax": {
                        "url": "/Pages/Requisitions.aspx/GetOpenRequisitionData",
                        "type": "POST"
                    },
                    "columns": [
                        { 'data': 'ReqId' },
                        { 'data': 'RequisitionTitle' },
                        { 'data': 'City' },
                        { 'data': 'Country', },
                        { 'data': 'DateCreated' },
                    ]
                });
            });
        };

HTML

<table id="bootstrap-data-table" class="display" style="width:100%">
   <thead>
       <tr>
          <th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">ReqId</th>
          <th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">Requisition Title</th>
          <th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">City</th>
          <th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">Country</th>
          <th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">Date Created</th>
       </tr>
    </thead>
 </table>

【问题讨论】:

  • 先尝试调试您的返回数据,然后尝试将可排序的 false 放入列中并更新答案

标签: c# jquery asp.net ajax datatables


【解决方案1】:

尝试添加一个 tbody 标签。我认为这是 DataTables 所必需的:

<div>
    <table id="myTable" class="table table-striped table-bordered" style="width:100%">
        <thead>
            <tr>
                <th>Identifier</th>
                <th>Description</th>
            </tr>
        </thead>
        <tbody id="TableBody"></tbody>
    </table>
</div>

【讨论】:

    猜你喜欢
    • 2016-02-08
    • 2014-11-04
    • 2018-10-31
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 2014-07-04
    相关资源
    最近更新 更多