Javascript DataTables无法读取属性';长度';未定义的

Javascript DataTables无法读取属性';长度';未定义的,javascript,jquery,asp.net,datatables,jquery-datatables,Javascript,Jquery,Asp.net,Datatables,Jquery Datatables,下面是文档就绪功能 Script type="text/javascript" charset="utf-8"> $(document).ready(function () { $('#example').dataTable({ "bProcessing": true, "bServerSide": true, "sAjaxSource": "GetUser.ashx",

下面是文档就绪功能

Script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
        $('#example').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "GetUser.ashx",
            "sServerMethod": "POST",
            "sAjaxDataProp" : "",
            "aoColumnDefs": [ {
            "aTargets": [ 0 ],
            "mData": "download_link",
            "mRender": function ( data, type, full ) {
               return '<a href="/UserDetail.aspx?ID='+data+'">Detail</a>';
             }
           } ],
            "aoColumns": [
                { "mData": "LoginId" },
                { "mData": "Name" },
                { "mData": "CreatedDate" }
            ]
        });
下面是html表格,数据应该放在这里

<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
             <th width="15%">User Detail</th>
            <th width="15%">LoginID</th>
            <th width="15%">Name</th>
            <th width="15%">Created Date</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="5" class="dataTables_empty">Loading data from server</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
             <th width="15%">User Detail</th>
            <th width="15%">LoginID</th>
            <th width="15%">Name</th>
            <th width="15%">Created Date</th>
        </tr>
    </tfoot>
</table>
当我进一步检查时,它来自jquery.dataTables.js的第2037行

var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );


我检查了json是否有效,但“aData”为空,为什么会出现这种情况?

由于有4列,请在“aoColumns”中添加以下内容:

对于未定义的长度,我已经尝试了以下代码,并且可以正常工作:

$('#example').dataTable({
 "aLengthMenu": [[100, 200, 300], [100, 200, 300]],
  "iDisplayLength": 100,
  "iDisplayStart" : 0,
  "bProcessing": true,
  "bServerSide": true,
  "sAjaxSource": "GetUser.ashx",
  "sServerMethod": "POST",
  "sAjaxDataProp" : "",
  "aoColumnDefs": [ {
    "aTargets": [ 0 ],
    "mData": "download_link",
    "mRender": function ( data, type, full ) {
      return '<a href="/UserDetail.aspx?ID='+data+'">Detail</a>';
    }
  } ],
  "aoColumns": [
    { "mData": null },
    { "mData": "LoginId" },
    { "mData": "Name" },
    { "mData": "CreatedDate" }
  ]
});
$('#示例')。数据表({
“阿伦提努”:[[100200300],[100200300],
“iDisplayLength”:100,
“iDisplayStart”:0,
“bProcessing”:正确,
“bServerSide”:正确,
“sAjaxSource”:“GetUser.ashx”,
“sServerMethod”:“POST”,
“sAjaxDataProp”:“,
“aoColumnDefs”:[{
“目标”:[0],
“mData”:“下载链接”,
“mRender”:功能(数据、类型、完整){
返回“”;
}
} ],
“aoColumns”:[
{“mData”:null},
{“mData”:“LoginId”},
{“mData”:“Name”},
{“mData”:“CreatedDate”}
]
});
要了解更多有关阿伦哲努的信息,请访问以下参考网站:

您的
“sAjaxDataProp”:“
被设置为空字符串,这会导致此错误

dataTables希望在这里有一个字符串,告诉您可以在哪个键下找到服务器返回的数据。 这默认为aaData,因此您的json应该包括该键以及分页等可能返回或需要的所有其他键

普通服务器端json:

{
"iTotalRecords":"6",
"iTotalDisplayRecords":"6",
"aaData": [
    [
        "1",
        "sameek",
        "sam",
        "sam",
        "sameek@test.com",
        "1",
        ""
    ],...
因为所有值都在aaData中,所以根本不需要sAjaxDataProp

修改的服务器端json:

{
"iTotalRecords":"6",
"iTotalDisplayRecords":"6",
"myData": [
    [
        "1",
        "sameek",
        "sam",
        "sam",
        "sameek@test.com",
        "1",
        ""
    ],
现在这些值在myData中。因此,您需要通过设置告诉dataTables在何处查找实际数据:

"sAjaxDataProp" : "myData"

这里是一个

使用
$(“#示例”).DataTable({..
(大写D)而不是
$(“#示例”).DataTable({..

如果您看到此错误,请查看从服务器返回的json,然后确保您的所有DataTable“mData”值都有匹配的条目。如果您也在使用bean,请检查该条目

而且不需要为表指定“tr”、“td”等。如果让jquery为您这样做,会更干净。下面是我的表的外观:

<table cellpadding="0" cellspacing="0" border="0" class="display" id="myTable" style="table-layout:fixed" ></table>

当我遇到这个问题时,它实际上是一个未应用迁移的结果。我已经恢复了数据库的备份,其中还没有运行我最近的架构迁移,一旦我运行了迁移,一切都正常。

您可以查看调用堆栈并追溯到网页问题的根源……下面是ng属性没有用逗号分隔。这是一种类型吗?
“电子邮件”:“白色”。smith@logical.com“CreatedDate:“2014年1月21日12:03:00 PM”“EntityState:“2”,“EntityKey:“System.Data.EntityKey”
@Nilesh这不是一种类型,只是我忘了在这篇文章中添加逗号,我已经在这里添加了逗号。对不起,我的意思是输入错误而不是类型:)依赖版本DT,看
{
"iTotalRecords":"6",
"iTotalDisplayRecords":"6",
"myData": [
    [
        "1",
        "sameek",
        "sam",
        "sam",
        "sameek@test.com",
        "1",
        ""
    ],
"sAjaxDataProp" : "myData"
<table cellpadding="0" cellspacing="0" border="0" class="display" id="myTable" style="table-layout:fixed" ></table>
{sTitle: "Column A", sWidth: "100px", mData: "idStringFromJson", bSortable: false},