数据表服务器端请求始终为GET

时间:2016-01-30 03:17:37

标签: jquery ajax datatables

我有以下数据表配置,

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 datatables版本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和数据表配置,在这种情况下,参数内容采用json对象格式,并且它不会将请求发送到ajax配置中的指定URL。请参阅从firebug控制台捕获的附图。

enter image description here

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

编辑:更新

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

$('.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
                ]
            });

2 个答案:

答案 0 :(得分:0)

processing : true后有逗号丢失,很可能就是原因。

答案 1 :(得分:0)

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