enter image description here我有一个json数据,我希望使用ajax在数据表中显示。屏幕仅显示加载数据,但实际上它不加载数据。这是我的数据表代码。
$(document).ready(function(){
$('#example').DataTable( {
"bProcessing": true,
// "bServerSide": true,
"sAjaxSource": "all_data.php",
// "sAjaxDataProp": "data"
"aoColumns": [
{ "mDataProp": "id" },
{ "mDataProp": "Vendor Code" },
{ "mDataProp": "Vendor Name" },
{ "mDataProp": "Category/Season" },
{ "mDataProp": "Product" },
{ "mDataProp": "Price" },
{ "mDataProp": "BLP" } ,
{ "mDataProp": "Quote Sent By" },
{ "mDataProp": "Sent On" },
{ "mDataProp": "Sent To" },
{ "mDataProp": "Link" }
]
} );
});
这是我的json文件
[{"id":"1","vendor_code":"PBH053","vendor_name":"Specialty Polyfilms","category":"Food Wrap","product":"briefs","price":"0","blp":"GBP 0.290","quote_sent_by":"Martie Sir","quote_sent_on":"2023-09-16","sent_to_buyer":"Sarah spencer","Link":"link"},{"id":"2","vendor_code":"PBH055","vendor_name":"Specialty Polyfilms","category":"Food Wrap","product":"briefs","price":"0","blp":"GBP 0.290","quote_sent_by":"Martie Sir","quote_sent_on":"2023-09-16","sent_to_buyer":"Sarah spencer","Link":"link"}]
这是我的HTML
<table width="100%" id="example" class="display" cellspacing="0">
<thead>
<tr>
<th>#</th>
<th>Vendor Code</th>
<th>Vendor Name</th>
<th>Category/Season</th>
<th>Product</th>
<th>Price</th>
<th>BLP</th>
<th>Quote Sent By</th>
<th>Sent On</th>
<th>Sent To</th>
<th>Link</th>
</tr>
</thead>
<tfoot>
<tr>
<th>#</th>
<th>Vendor Code</th>
<th>Vendor Name</th>
<th>Category/Season</th>
<th>Product</th>
<th>Price</th>
<th>BLP</th>
<th>Quote Sent By</th>
<th>Sent On</th>
<th>Sent To</th>
<th>Link</th>
</tr>
</tfoot>
</table>
php code
<?php
require("connection.php");
$data=array();
$query="SELECT * FROM quote_system";
$result=mysqli_query($dbCon,$query)or die(mysqli_error($dbCon));
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$row['id'];
$row['vendor_code'];
$row['vendor_name'];
$row['category'];
$row['product'];
$row['price'];
$row['blp'];
$row['quote_sent_by'];
$row['quote_sent_on'];
$row['sent_to_buyer'];
$row['Link'];
$data[]=$row;
}
//print_r($data);
//$data= $data.map(JSON.parse);
echo json_encode($data);
?>