我有以下數據表的配置,數據表服務器側請求總是GET
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。查看從螢幕控制檯捕獲的附加圖像。
感謝您的幫助來排序了這一點。
編輯:更新
好像這是因爲列過濾器插件的發生。在之前的數據表初始化之後,我立即擁有以下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
]
});
不,情況並非如此。我編輯了這個問題。 – Anuruddha