0

I am trying to populate a table from the DataTables js library. The data is extracted by the php script which I pass as the ajax parameter, just like the example on the datatables site specifies.

However, I get the error that the response is not valid json. Looking at my dev tools, I can see that it is not! In fact, the response is simply the complete contents of the php script which is suppose to run and return some data.

So, the DataTables function is seeing the ajax parameter as a source of the data (and thus tries to interpret it as json) and not a script to run, which will return the data.

What am I doing wrong?

Here is the javascript which calls the php:

$("#dataBilling").DataTable({
 "processing":true,
  "serverSide": true,
  "ajax":"scripts/readfromdb.php"
});

The contents of readfromdb.php is not relevant, since no matter what it is, it is not even being executed. Like I said, devtools shows the XHR response as the entire contents of that php file.

user3064874
  • 125
  • 1
  • 11
  • If you open php file in a new tab (`yoursite.com/scripts/readfromdb.php`) - what do you see? – u_mulder Sep 29 '17 at 11:51
  • I am just seeing the contents of the php file. It is not trying to run or anything – user3064874 Sep 29 '17 at 11:54
  • Ah, faulty php installation. I did not realise the fault was with the php and not with some datatables feauture. Will browse to php file as a test in the future to find this quicker. You'r duplicate questions solved my problem – user3064874 Sep 29 '17 at 12:03

0 Answers0