gpt4 book ai didi

java - 数据表警告 : table id=example - Ajax error

转载 作者:行者123 更新时间:2023-12-02 01:59:33 25 4
gpt4 key购买 nike

我正在使用 jquery Datatables,但收到此错误:DataTables 警告:表 id=example - Ajax 错误。这是 MVC 应用程序。数据来自MSQL数据库。 chrome 的控制台没有错误。也许这是一个语法问题?这是我的 .jsp 文件:

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
<title></title>

<script>
function confirmDelete(id) {
if (confirm("Are you sure to delete this cost?")) {
window.location.href = "/cost/delete/" + id;
}
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="../../resources/js/datatable.js"></script>

</head>
<body>

<table id="example" class="display" style="width:80%">
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>MPK</th>
<th>Account</th>
<th>Client</th>
<th>Amount</th>
<th>Description</th>
<th>Payment</th>
<th>Invoice Number</th>
<th>Department</th>
<th>Delete</th>
<th>Edit</th>

</tr>
</thead>
<tbody>
<c:forEach var="costs" items="${allcosts}">
<tr>
<td>${costs.id}</td>
<td>${costs.salesDate.toString()}</td>
<td>${costs.mpk.code}</td>
<td>${costs.account.code}</td>
<td>${costs.client.name}</td>
<td>${costs.amount.toString()}</td>
<td>${costs.description.toString()}</td>
<td>${costs.payment.type}</td>
<td>${costs.invoiceNumber.toString()}</td>
<td>${costs.department.name}</td>
<td><a href="#" onclick="confirmDelete(${costs.id}, '${costs.id}')">Delete</a></td>
<td><a href="/cost/update/${costs.id}">Edit</a></td>
</tr>
</c:forEach>
</tbody>
</table>

<spring:url value="/report/?type=xls" var="xlsURL"/>
<a href="${xlsURL }">Download Excel</a>

</body>
</html>

这是我的 .js 文件:

    $(document).ready(function () {
$('#example').DataTable({
"processing": true,
"serverSide": true,
"pageLength": 5,
"ajax": {
"url": "/cost/all",
"columns": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
{"data": "Delete"},
{"data": "Edit"}
]
} });
});

如何解决这个问题?我被困住了。

最佳答案

改用以下初始化代码:

$(document).ready(function () {
$('#example').DataTable({
pageLength: 5
});
});

关于java - 数据表警告 : table id=example - Ajax error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57381756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com