URGENT - Basic Ajax Question
URGENT - Basic Ajax Question
I have a json response as shown below and when I tie it to the datatable I am getting error "Cannot read property 'length' of undefined" I know DataTable is looking for "Data" field but I am not able to change the source. Any ideas greatly appreciated. Here is the basic code:
$(document).ready(function () { $('#EventLog').DataTable({ "destroy": true, "ajax": "../../api/logs/getlog" }); });And Data is:
[{"EventDate":"2016-11-02T09:06:00","Message":"upgrade libisc-export160:amd64 1:9.10.3.dfsg.P4-8ubuntu1.1 1:9.10.3.dfsg.P4-8ubuntu1.2","ID":1,"Severity":"High","System":"Mysql"},{"EventDate":"2016-11-02T09:06:00","Message":"status triggers-pending libc-bin:amd64 2.23-0ubuntu3","ID":2,"Severity":"Information","System":"Apache"}]
Replies
This will not work, DataTable expects a structure like this...
Actually, unless you are using server-side processing (
init serverSide
), yes, that data structure is acceptable to DataTables using theajax.dataSrc
option set to be an empty string (telling DataTables to expect a flat array rather than looking inside an object property for an array).There is an example of that available here.
Allan