我正在尝试从mysql数据库填充我的数据表。一切正常,但是当我尝试查看我的桌子时,它说:
DataTables警告:表id = manageProductTable-无效的JSON响应。
有关此错误的更多信息,请参见http://datatables.net/tn/1
我已经检查过控制台,可以在其中看到我的列表:
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
$('#manageProductTable').DataTable({
ajax: {
'url': 'php_action/fetchProduct.php',
'dataSrc': 'features'},
'columns': [
{"data":"Name"},
{"data":"Code"},
{"data":"Brand"},
{"data":"Quantity"},
{"data":"Price"},
]
});
PHP
$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);
我还有一个php文件,但这只是用来构建网页。
答案 0 :(得分:0)
在那里做什么“连接成功”? 那改变了你的反应。