尝试使用php ajax mysql填充数据表
我正在尝试从mysql数据库填充我的datatable。一切正常,但当我试着看我的桌子时,它说: DataTables警告:表id=manageProductTable-JSON响应无效 有关此错误的详细信息,请参阅http://datatables.net/tn/1 我已经检查了console,我可以在那里看到我的列表:尝试使用php ajax mysql填充数据表,php,mysql,Php,Mysql,我正在尝试从mysql数据库填充我的datatable。一切正常,但当我试着看我的桌子时,它说: DataTables警告:表id=manageProductTable-JSON响应无效 有关此错误的详细信息,请参阅http://datatables.net/tn/1 我已经检查了console,我可以在那里看到我的列表: connection success { "data": [ ["tulum","rtert","6","12.30","dfsdfsdf"],
connection success {
"data": [
["tulum","rtert","6","12.30","dfsdfsdf"],
["body","bd56","8","56,30","dfsdfsdf"],
["dfdsf","dsfdsf","8","56,32","dsfdsfsd"],
["","saf","8","25.90","dsfdsfsd"],
["tulum","FWNWP","","","dsfdsfsd"],
["bluz","dd56","6","78","dsfdsfsd"],
["dsfdsf","sdfsdf","9","23","chicco"],
["atlet","ATL30","30","23,30","chicco"],
["BODY","56FG","6","56,30","dsfdsfsd"]
]
}
那么我做错了什么
JS
PHP
我还有一个php文件,但它只是用来构建网页。那里的“连接成功”是怎么回事?
这改变了您的响应。这是我的数据库连接控制。谢谢
$('#manageProductTable').DataTable({
ajax: {
'url': 'php_action/fetchProduct.php',
'dataSrc': 'features'},
'columns': [
{"data":"Name"},
{"data":"Code"},
{"data":"Brand"},
{"data":"Quantity"},
{"data":"Price"},
]
});
$sql = "SELECT product.product_id, product.product_name,
product.product_code, product.brand_id,
product.quantity, product.price, brand.brand_name
FROM product
INNER JOIN brand ON product.brand_id = brand.brand_id";
$result = $connect->query($sql);
$output = array('data' => array());
if($result->num_rows > 0) {
$active = "";
while($row = $result->fetch_array()) {
$brandName = $row[6];
$output['data'][]= array(
$row[1],
$row[2],
$row[4],
$row[5],
$brandName,
);
}
}
$connect->close();
echo json_encode($output);