jquery.dataTables.min.js:48 Uncaught TypeError: Cannot read property 'length' of undefi

jquery.dataTables.min.js:48 Uncaught TypeError: Cannot read property 'length' of undefi

smgeislersmgeisler Posts: 3Questions: 1Answers: 0

HI, I'm getting this error, "jquery.dataTables.min.js:48 Uncaught TypeError: Cannot read property 'length' of undefined".
I believe it is able to read the json data. If I remove the json data file from the server I get a 404 error. So it at least finds the file.find

Here's the log from Chrome:

jquery.dataTables.min.js:48 Uncaught TypeError: Cannot read property 'length' of undefined
(anonymous function) @ jquery.dataTables.min.js:48
i @ jquery.dataTables.min.js:35
n.success @ jquery.dataTables.min.js:35
i @ jquery.min.js:2
j.fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4

Here's my json data
{"tradelist":[
{"station":"KELO", "producer":"PAMS", "package":"14", "mediano":"R-34-02"},
{"station":"KELO", "producer":"PAMS", "package":"Windy (WLS'76)", "mediano":"R149-006"},
{"station":"KELO", "producer":"PAMS", "package":"Windy", "mediano":"R149C-006"},
{"station":"KELO", "producer":"PAMS", "package":"14", "mediano":"R398-002"},
{"station":"KELO", "producer":"PAMS", "package":"10", "mediano":"R413-004"}
]}

Here's the html:

<!DOCTYPE html>
<html>

<head>

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">

</head>

<body>

Station Producer Package Media No
$(document).ready(function() { $('#tradelist').DataTable( { "ajax": { "url": "tradelist.json", "type": "POST" } } ); } );

</body>

</html>

Thanks,
Steve

This question has an accepted answers - jump to answer

Answers

  • smgeislersmgeisler Posts: 3Questions: 1Answers: 0

    Here's a link to test:
    http://560.com/guestbook.htm

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin
    Answer ✓

    By default DataTables will look for a property called data in the returned Ajax object (manual). You can change that using the ajax.dataSrc option - in this case you would want to set it to be tradelist.

    Since you are using objects for the data, you would also need to use columns.data to tell DataTables which property belongs to each column - manual.

    Allan

  • smgeislersmgeisler Posts: 3Questions: 1Answers: 0

    That fixed it. I get it now. Thanks for your help.

This discussion has been closed.