I am trying to implement the basic json data source. It's not working.
I am trying to implement the basic json data source. It's not working.

I'm trying to use DataTables for the first time ever. I've created a simple php script that pulls every row from the database and uses json_encode($result) to encode the data to json format. I'm not getting a result at all.
The script outputs to:
jonathanryangrice.com/trips/retrieve.php
The page that is suppose to show the data in a table is:
jonathanryangrice.com/trips/retrieve.html
I know there are errors. I can't seem to fix them. Any help would be appreciated.
This question has an accepted answers - jump to answer
Answers
Your table has 8 columns, your json has 9 fields. They have to match.
Also your HTML is invalid: table must have "tbody" tags.
if the last line of your retrieve.php is like that
echo json_encode($result);
change to this
echo '{"data":'.json_encode($result).',"options":[],"files":[]}';
I think you need to put your JSON into a data object so it will look something like this:
{data: [{id: "36",....}, {id: "37",....}]}
Kevin
Thanks sinanktp. It worked with your answer. However. It wouldn't work with the full echo line.
echo '{"data":'.json_encode($result).',"options":[],"files":[]}';
but only
echo '{"data":'.json_encode($result).'}';
Thanks again.
It really depends exactly on what is in
$result
. jsonlint.com is what I use to validate JSON and find any errors.Allan