Cannot read property 'length' of undefined while data exists
Cannot read property 'length' of undefined while data exists
nava1021
Posts: 9Questions: 0Answers: 1
Hi,
I get Cannot read property 'length' of undefined error message while using datatable. The ajax url successfully fetches the JSON data and columns are mapped correctly as the names obtained from the server.
Here is the returned object
{
"d": "[{\"title\":\"Basic Price\",\"effectiveDate\":\"2016-06-20\",\"row_id\":8,\"value\":10,\"sector\":\"REAL\",\"fiscalYear\":\"2016/17\",\"remarks\":\"\"}]"
}
However, When I use dataSrc:''
property next to data, the error message goes but nothing is displayed in the datatable.
Here is my code
var DTO = { id: indicatorID, sector: sector };
$('#main_data').dataTable({
ajax:
{
url: "AddGDP.aspx/GetMainData",
type: "POST",
contentType: "application/json;",
data: function () {
return JSON.stringify(DTO);
}
},
});
debug link : http://debug.datatables.net/uxaqum
This discussion has been closed.
Replies
I'm not clear why you are trying to stringify a string :-). I think you want to parse it!
Try:
Allan
Many Thanks Allan as usual.
I must admit I forgot to JSON.parse the returned JSON string. I changed the code to the following and voila it worked....
Thanks for assisting and saving my time and patience
datatable Allan
Nava
Oops - yes,
ajax.dataSrc
! Good to hear you got it working :-)Allan