[英]DataTables Invalid JSON response v2
function fetch_data() {
var dataTable = $('#Acc_data').DataTable({
"bPaginate": false,
"info": false,
"processing": true,
"serverSide": true,
"order": [],
"ajax": {
url: "fetch_acc.php",
type: "POST",
"dataSrc": ""
}
});
}
HTML代碼
<table class="table" id="Acc_data" style="margin-left:30px;">
<thead class=" text-primary text-center">
<tr>
<th>
Account#
</th>
<th>
Status
</th>
<th>
Assigned_To
</th>
<th></th>
</tr>
</thead>
</table>
PHP代碼
while($row = mysqli_fetch_array($result))
{
$sub_array = array();
$sub_array[] = '<div contenteditable class="update text-center" data-id="'.$row["id"].'" data-column="Account#">' . $row["Accno"] . '</div>';
$sub_array[] = '<div contenteditable class="update text-center" data-id="'.$row["id"].'" data-column="Status">' . $row["stat"] . '</div>';
$sub_array[] ='<div contenteditable class="update text-center" data-id="'.$row["id"].'" data-column="Assigned_To">' . $row["email"] . '</div>';
$sub_array[] = '<button type="button" name="delete" class="btn btn-danger btn-xs delete" id="'.$row["id"].'"><i class="fa fa-trash" aria-hidden="true"></i></button>';
$data[] = $sub_array;
}
$output = array(
"data" => $data
);
echo json_encode($output);
這會產生錯誤“DataTables 警告:table id=Acc_data - 無效的 JSON 響應。有關此錯誤的更多信息,請參閱http://datatables.net/tn/1 ”。 我搜索了很多,但沒有找到我做錯的地方。 任何形式的幫助將不勝感激。 提前致謝
我相信錯誤可能是由於您如何構建 HTML。 DataTables 需要特定的布局才能工作:
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
</tbody>
</table>
以上摘自: https : //datatables.net/manual/installation#HTML
所以那些<div>
's 而不是<td>
's 可能會導致問題。
您能否也發布一個從查詢返回的數據樣本?
這是我通過的查詢中的錯誤。 感謝每一位的熱情回應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.