"Cannot read property 'length' of undefined" with Ajax source
"Cannot read property 'length' of undefined" with Ajax source
tsnieman
Posts: 1Questions: 0Answers: 0
Hey there,
Have been recently trying to get this working for a project I'm working on and haven't had much luck. I'm not quite sure what the issue is at all at this point.
I have data stored like this:
[code][
{ "label":"9-hydroxy-risperidone",
"x":0,
"y":1.5051929155586775E-4,
"z":"42.0",
"cond":"treatment",
"selected":0,
"term":"9-hydroxy-risperidone",
"star":0,
"conceptId":"13697"
},
... (more data)[/code]
A table like this
[code]
Date
Treatment
Strength of Evidence
Patients
Studies
06/10/11
Treatment 3
Evidence 07/10
345
428
[/code]
And jQuery like this
[code] $(document).ready(function() {
var oTable = $('#tablechart').dataTable( {
"bDestroy": true,
"bProcessing": true,
"sAjaxSource": "/static/data.txt",
"aoColumns": [
{ "mDataProp": "label" },
{ "mDataProp": "x" },
{ "mDataProp": "y" },
{ "mDataProp": "z" },
{ "mDataProp": "cond" }
]
});
});[/code]
But I get an error like this in the Chrome console:
[code]Uncaught TypeError: Cannot read property 'length' of undefined
i.fn.dataTable.a._bInitComplete datatables.js:4
c.extend.handleSuccess main.js:7
c.extend.ajax.L.w.onreadystatechange main.js:7[/code]
I'm absolutely out of ideas. Any clue what's going on?
Thanks!
Have been recently trying to get this working for a project I'm working on and haven't had much luck. I'm not quite sure what the issue is at all at this point.
I have data stored like this:
[code][
{ "label":"9-hydroxy-risperidone",
"x":0,
"y":1.5051929155586775E-4,
"z":"42.0",
"cond":"treatment",
"selected":0,
"term":"9-hydroxy-risperidone",
"star":0,
"conceptId":"13697"
},
... (more data)[/code]
A table like this
[code]
Date
Treatment
Strength of Evidence
Patients
Studies
06/10/11
Treatment 3
Evidence 07/10
345
428
[/code]
And jQuery like this
[code] $(document).ready(function() {
var oTable = $('#tablechart').dataTable( {
"bDestroy": true,
"bProcessing": true,
"sAjaxSource": "/static/data.txt",
"aoColumns": [
{ "mDataProp": "label" },
{ "mDataProp": "x" },
{ "mDataProp": "y" },
{ "mDataProp": "z" },
{ "mDataProp": "cond" }
]
});
});[/code]
But I get an error like this in the Chrome console:
[code]Uncaught TypeError: Cannot read property 'length' of undefined
i.fn.dataTable.a._bInitComplete datatables.js:4
c.extend.handleSuccess main.js:7
c.extend.ajax.L.w.onreadystatechange main.js:7[/code]
I'm absolutely out of ideas. Any clue what's going on?
Thanks!
This discussion has been closed.
Replies
"DataTables expects an object with an array called "aaData" with the data source."
This should fix your ajax/JSON:
[code]
{
aaData: [
{ "label":"9-hydroxy-risperidone",
"x":0,
"y":1.5051929155586775E-4,
"z":"42.0",
"cond":"treatment",
"selected":0,
"term":"9-hydroxy-risperidone",
"star":0,
"conceptId":"13697"
},
... (more data)
[/code]