Loading an array of objects via Ajax gives error
Loading an array of objects via Ajax gives error

I have simple API endpoint that returns data in the following format:
[{id: 1, name: "this", code:" that"}, {id: 2, name: "what", code: "where"}]
If I made this data static within the page, DataTables displays it fine, using the columns
property to state where the data comes from.
When I load it via AJAX, an error is thrown. The shape of my response data seems to match the simple array of data example in the manual - https://www.datatables.net/manual/ajax
Example here - comment out the ajax
and dataSrc
props and uncomment the data
prop to switch between the two loading methods.
http://live.datatables.net/qasabufo/2/edit?html,js,console,output
This question has an accepted answers - jump to answer
Answers
The
ajax.dataSrc
is part of a configuration object for theajax
option. In your example you have this:You need to combine the url and dataSrc into one object like this:
Kevin
@kthorngren -- that's the one! Thanks very much. Stared at it for so long I didn't even spot it.