我有一个使用dataTables构建的表,数据来自 AJAX 属性,但是,我在ajax上得到一个错误:
第一个月
的数据
我不知道为什么会这样。下面是我的代码:
<script src="https://cdn.datatables.net/1.13.5/css/jquery.dataTables.min.css"></script>
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
<script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<script>
$(document).ready(function () {
const getToken = localStorage.getItem("token");
const accountType = localStorage.getItem("acc_type");
console.log("GET TOKEN", getToken);
var table = $("#example").DataTable({
processing: true,
serverSide: true,
ajax: {
url: "http://192.168.30.03:3000/api/log/list",
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=UTF-8',
data: JSON.stringify({
limit: 13,
offset: 1,
search: "",
id: 0,
start_id: 0,
end_id: 0,
event: "",
user: "",
message: "",
type: "",
start_time: "",
end_time: "",
order_by: "desc",
order_column: "id"
}),
headers: {
'Authorization': 'Bearer ' + getToken
},
success: function (response) {
console.log("SUCCESS", response);
},
error: function (response) {
console.log("ERROR", response);
},
columns: [
{ data: "id", title: "id" },
{ data: "event", title: "event" },
{ data: "user", title: "user" },
{ data: "message", title: "message" },
{ data: "type", title: "type" },
{ data: "created_at", title: "created_at" },
],
},
});
table.draw();
});
</script>
字符串
1条答案
按热度按时间nimxete21#
字符串