dataTable不显示正确的ajax数据 [英] dataTable not doesnt display ajax data correct
本文介绍了dataTable不显示正确的ajax数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用DataTables,并希望使用Ajax加载我的数据.但是加载页面时出现此错误:
I am using DataTables and want to use Ajax to load my data. But I get this error when I load the page:
DataTables警告:表id = example-请求的第0行第0列的未知参数'DocentID'.有关此错误的更多信息,请参见 http://datatables.net/tn/4
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"}
]
});
});
我的ajax.php文件及其回声
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);
数组:
["{\"0\":\"0\",\"DocentID\":\"0\"}","{\"0\":\"67\",\"DocentID\":\"67\"}","{\"0\":\"0\",\"DocentID\":\"0\"}","{\"0\":\"0\",\"DocentID\":\"0\"}"]
推荐答案
尝试删除第一个json_encode()
.无需对其进行两次编码.
Try removing the first json_encode()
. There's no need to encode it twice.
include_once('DB_Handler.php');
$result = mysqli_query($mysqli, "SELECT DocentID FROM gebruiker");
$rows = array();
while ( $row = mysqli_fetch_array($result))
{
$rows[] = $row;
}
echo json_encode($rows);
这篇关于dataTable不显示正确的ajax数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文