1

I want to implement datatables but i am getting the following error:

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)

My implementation looks like this:

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" }
          ]
})

This is the JSON getting loaded into the datatable:

[{"Members":[{"Code":"001","Name":"Bay","Email":"[email protected]"},{"Code":"00458","Name":"Beng","Email":"[email protected]"}]}]
2
  • 1
    You are attempting to access the length property of something. This is not shown in the snippet you have given, please provide all your code Commented Mar 5, 2018 at 14:07
  • @wmash you are thinking wrong all need for solutions writed but you dont even look give negative Commented Mar 5, 2018 at 14:21

1 Answer 1

2

Usually this means that jQuery DataTables cannot find the data in the response to the Ajax request, see TypeError: Cannot read property ‘length’ of undefined for more information.

Use the following value for ajax.dataSrc option:

"dataSrc": "0.Members"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.