Trying to figure this out, but all I'm getting is [Object object]. Can anyone assist me with this issue? I've been following the Datatables documentation, but still can't seem to get it right. Any help would be greatly appreciated... thanks
Here's my code:
Javascript
$(document).ready(function() {
$.ajax({
url: "includes/view_ajax.php",
type: "POST",
cache: false,
dataType: 'json',
success: function(dataResult){
alert( JSON.stringify(dataResult) );
$('#memberdata').DataTable({
"searching": true,
"aaData": [dataResult],
"aoColumns": [
{ "sTitle": "PlateNo" },
{ "sTitle": "Make" },
{ "sTitle": "Series" }
]
});
}
});
PHP
<?php
$columns = array(
// datatable column index => database column name
0 => 'PlateNo',
1 => 'Make',
2 => 'Series',
);
include 'database.php';
$sql = "SELECT * FROM vehicleinfo";
$res = mysqli_query($conn, $sql) or die("Error: ".mysqli_error($conn));
$dataArray = array();
while( $row = mysqli_fetch_array($res) ) {
$PlateNo = $row["PlateNo"];
$Make = $row["Make"];
$Series = $row["Series"];
$dataArray [] = array("PlateNo" => $PlateNo,
"Make" => $Make,
"Series" => $Series);
}
echo json_encode($dataArray);
?>