I am trying to populate datatable on some button click with data from the database.
However the following code is working [using text file]
-----Javascript:-----
$('#tblData').dataTable( {
"bProcessing": true,
"sAjaxSource": 'data.txt'
} );
-----data.txt-----
{
"aaData": [
[
"row 1 col 1 data",
"row 1 col 2 data",
"row 1 col 3 data",
"row 1 col 4 data"
],
[
"row 2 col 1 data",
"row 2 col 2 data",
"row 2 col 3 data",
"row 2 col 4 data"
],
[
"row 3 col 1 data",
"row 3 col 2 data",
"row 3 col 3 data",
"row 3 col 4 data"
]
]
}
How to pass such data fom php ??
The following code is not working [using php/mysql]
-----Javascript-----
$('#tblData').dataTable( {
"bProcessing": true,
"sAjaxSource": 'response.php'
} );
------response.php------
include_once("config.php");
$dataArr = array();
$query = "SELECT data1,data2,data3,data4 from tbl_data";
$result = $conn->query($query);
$result->data_seek(0);
while($row = $result->fetch_array(MYSQLI_ASSOC)){
$ dataArr [] = $row; // ?? What to do here?
}
echo json_encode($dataArr);
how to make it working ??