【问题标题】:Datatables server side request is always GET数据表服务器端请求始终是 GET
【发布时间】:2016-01-30 03:17:37
【问题描述】:

我有以下数据表配置,

var userTable = $('.dataTables-user').DataTable({
            responsive: true,
            orderCellsTop: true,
            autoWidth: false,
            serverSide : true,
            processing : true,
            ajax: {
                "url": "/wifi/users/get",
                "type": "POST"
            },
            columns: [
                {"data": "username", "width": "15%"},
                {"data": "acl", "width": "7%"},
                {"data": "groupname", "width": "10%"},
                {"data": "visits", "width": "5%"},
                {"data": "acctstarttime", "width": "10%"},
                {"data": "acctstoptime", "width": "10%"},
                {"data": "acctlastupdatedtime", "width": "10%"}
            ],
            dom: 'T<"clear">lfrtip',
            tableTools: {
                "sSwfPath": "js/plugins/dataTables/swf/copy_csv_xls_pdf.swf"
            }
        });

根据配置,服务器端请求应该是POST。这会在初始表加载中生成一个 POST。然而,在(排序、搜索、分页)期间发生的所有后续调用都是 GET 请求,并且目标 url 不是 ajax 中指定的,而是 window.location.href。

我正在使用 jquery 数据表版本 1.10.7。我有以下导入的 js 库列表。

<script src="js/jquery-2.1.1.js"></script>
<script src="js/plugins/dataTables/jquery.dataTables.min.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="js/plugins/dataTables/dataTables.tableTools.min.js"></script>
<script src="js/plugins/dataTables/jquery.dataTables.columnFilter.js"></script>

这是预期的行为吗?

我尝试将后端相应地更改为 GET 和 datatables 配置,在这种情况下,参数内容是 json 对象格式,它不会将请求发送到 ajax 配置中的指定 URL。查看从 firebug 控制台捕获的附加图像。

感谢您帮助解决这个问题。

编辑:更新

似乎由于列过滤器插件而发生这种情况。在之前的数据表初始化之后,我立即有以下 js 代码,一旦我删除这部分问题就不会出现。是否可以让 columnfilter 插件和数据表服务器端一起工作?

$('.dataTables-user').dataTable().columnFilter({
                sPlaceHolder: "head:before",
                aoColumns: [
                    {"bSortable": false},
                    {type: "select", values: ['Whitelisted', 'Blacklisted', 'normal_user']},
                    {type: "select", values: locationGroups},
                    {"bSortable": false},
                    {"bSortable": false},
                    {"bSortable": false},
                    null,
                    null
                ]
            });

【问题讨论】:

    标签: jquery ajax datatables


    【解决方案1】:

    processing : true 后面少了一个逗号,很可能就是这个原因。

    【讨论】:

      【解决方案2】:

      发生这种情况是因为,列过滤器插件已覆盖服务器端处理功能,并且它与较新版本的数据表 (1.10+) 不兼容。我已经从插件中删除了覆盖的服务器端处理,并将修改后的版本发布在this github repo

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-20
        • 1970-01-01
        • 2018-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多