Odd Length Error
Odd Length Error
I am getting an error about length, I tried google searching it, but I couldn't figure it out.
Error:
Uncaught TypeError: Cannot read property 'length' of undefined
Code:
$objDatatable = $(".bulkSMSTable").DataTable({
ajax: {
url: "/manager/bulk_sms/bulk_sms.php?jsFunction=populateTable",
type: "POST",
contentType: 'application/json',
dataSrc: function (ajaxOutput) {
console.log(ajaxOutput);
},
error: function (jqXHR, exception, error) {
console.log('Error status:', jqXHR);
console.log('Exception: ' + exception);
console.log('Error message: ' + error);
}
},
"columns": [
{
"data": "date",
"title": "Date",
"orderable": true,
"width": "100px"
},
{
"data": "from",
"title": "From",
"orderable": true,
"width": "100px"
},
{
"data": "name",
"title": "Name",
"orderable": true
},
{
"data": "number",
"title": "Number",
"orderable": true,
"width": "100px"
},
{
"data": "message",
"title": "Message",
"orderable": false
},
{
"data": "status",
"title": "Status",
"orderable": true,
"width": "100px"
}
],
"dom": "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
"length": 50,
"order": [[0, 'desc']]
});
What am I doing wrong?
Answers
Guessing the problem is this:
When using
ajax.dataSrc
as a function you need to return something like the examples show. The error is likely caused by not returning anything.Kevin
it isreturning data. ajaxOutput contains a JSON object. I used dataSrc to se what the ajax call was returning, is that not it's purpose? If not, how do I see the output?
You can use
ajax.dataSrc
as a function to see the return JSON. The purpose ofajax.dataSrc
is to provide Datatables to the JSON data when its not at the expected data location. You also need to return the row data location as shown in the examples. If you don't return the data then the function will returnundefined
- the function is a standard Javascript function.Kevin
How do I see the returned data, and specify "columns"?
Without seeing your data its hard to say exactly but assuming its in the expected
data
property you would do this:Your columns will be defined based on your data structure. We can provide a more specific answer if you post an example of your data.
Kevin