小编use*_*360的帖子

DataTables警告:table = userTable - 无效的JSON响应?

我使用jQuery DataTables并收到此警告消息:

DataTables警告:table = userTable - 无效的JSON响应

servlet从MySQL中获取用户,我希望在jQuery Datatable中显示,但是Ajax无法解析JSON或者在servlet中生成错误的JSON?

Servlet的:

    List<UserDTO> users = this.service.getAllUser();
                Gson gson = new Gson();
                request.setAttribute("users", gson.toJson(users));
                request.getRequestDispatcher("listAllUser.jsp").forward(request, response);
Run Code Online (Sandbox Code Playgroud)

JSP:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Registered Users</title>
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script
        src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
    <link rel="stylesheet"
        href="http://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" />
    <link rel="stylesheet"
        href="http://code.jquery.com/ui/1.11.4/themes/flick/jquery-ui.css">
    <script>
        $(document).ready(function() {
            $('#userTable').dataTable({
                "processing" : true,
                "serverSide" : true,
                "ajax" : {
                    "url" : "ListAllUserServlet",
                    "type" : "POST"
                },
                "columns" …
Run Code Online (Sandbox Code Playgroud)

jquery jsp servlets datatables gson

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

datatables ×1

gson ×1

jquery ×1

jsp ×1

servlets ×1