I am using DataTables and want to use Ajax to load my data. But I get this error when I load the page:
DataTables warning: table id=example - Requested unknown parameter 'DocentID' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
I dont know what i'm doing wrong here is my Datatables script:
$(document).ready(function() {
$("#example").DataTable({
"ajax": {
"url": "assets/includes/ajax.php",
"dataSrc": ""
},
"columns": [
{"data": "DocentID"}
]
});
});
And my ajax.php file + what it echos
include_once('DB_Handler.php');
$result = mysqli_query($mysqli, "SELECT DocentID FROM gebruiker");
$rows = array();
while ( $row = mysqli_fetch_array($result))
{
$rows[] = json_encode($row);
}
echo json_encode($rows);
The array :
["{\"0\":\"0\",\"DocentID\":\"0\"}","{\"0\":\"67\",\"DocentID\":\"67\"}","{\"0\":\"0\",\"DocentID\":\"0\"}","{\"0\":\"0\",\"DocentID\":\"0\"}"]
Try removing the first
json_encode()
. There's no need to encode it twice.