未捕获的TypeError:无法读取未定义数据表的属性“长度”

问题描述 投票:1回答:1

我想实现数据表,但我收到以下错误:

jquery.dataTables.min.js:48 Uncaught TypeError: Cannot read property 'length' of undefined
at jquery.dataTables.min.js:48
at i (jquery.dataTables.min.js:35)
at Object.success (jquery.dataTables.min.js:35)
at u (jquery-3.3.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.3.1.min.js:2)
at k (jquery-3.3.1.min.js:2)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.min.js:2)

我的实现看起来像这样:

var oTable2 = $('#MyDataTable2').show().DataTable({
  "ajax": {
      "url": 'http://mvc/ComplaintHandlerSquadFind',                         
      "type": "GET",
      "dataSrc": "Members",
      "data": { Code : $('#input_1').val() }
  },
  "columns": [
      {"data": "Code"},
      { "data": "Name" },
      { "data": "Email" }
          ]
})

这是加载到数据表中的JSON:

[{"Members":[{"Code":"001","Name":"Bay","Email":"[email protected]"},{"Code":"00458","Name":"Beng","Email":"[email protected]"}]}]
jquery json ajax datatables
1个回答
1
投票

通常这意味着jQuery DataTables无法在响应Ajax请求时找到数据,有关详细信息,请参阅TypeError: Cannot read property ‘length’ of undefined

ajax.dataSrc选项使用以下值:

"dataSrc": "0.Members"
© www.soinside.com 2019 - 2024. All rights reserved.