how to solve "Uncaught TypeError: Cannot read property 'length' of undefined" this error.
how to solve "Uncaught TypeError: Cannot read property 'length' of undefined" this error.
maahi3391
Posts: 1Questions: 1Answers: 0
var $table = $('#productListTable');
//execute the below code only where we have table
if($table.length){
console.log('Inside the table !');
var jsonUrl = '';
if (window.categoryId == ''){
jsonUrl = window.contextRoot + '/json/data/all/products';
console.log(jsonUrl);
}
else{
jsonUrl = window.contextRoot + '/json/data/category/'+ window.categoryId +'/products';
console.log(jsonUrl);
}
$table.DataTable({
lengthMenu: [[3,5,10,-1], ['3 Records', '5 Records', '10 Records', 'All']],
pageLength: 5,
serverSide: true,
ajax: {
url: jsonUrl,
datasrc: ''
} ,
columns: [
{ data: 'name' },
{ data: 'brand'},
{ data: 'unitprice'},
{ data: 'quantity'}
]
});
This discussion has been closed.
Answers
First,
datasrc: ''
should bedataSrc: ''
with a capitalS
.https://datatables.net/reference/option/ajax.dataSrc
Second, if that doesn't fix your error then post the JSON that is returned from your server. Or use the Debugger and post the resulting URL.
Kevin