[英]Datatables server side ajax and sAjaxSource have different request parameter
我已經使用sAjaxSource參數通過服務器端處理制作了一個數據表。
$('#tbl-kamus').DataTable({
"processing": true,
"bServerSide": true,
"sAjaxSource": srcUri ,
...
當向服務器發出請求時,它將使用以下參數發送GET數據:
sEcho: 1
iColumns: 4
sColumns: ,,,,,,
iDisplayStart: 0
iDisplayLength: 30
mDataProp_0: 0
sSearch_0:
bRegex_0: false
bSearchable_0: true
bSortable_0: false
mDataProp_1: 1
sSearch_1:
bRegex_1: false
bSearchable_1: true
bSortable_1: true
mDataProp_2: 2
sSearch_2:
bRegex_2: false
bSearchable_2: true
bSortable_2: true
mDataProp_3: 3
sSearch_3:
bRegex_3: false
bSearchable_3: true
bSortable_3: false
sSearch:
bRegex: false
iSortCol_0: 1
sSortDir_0: desc
iSortCol_1: 2
sSortDir_1: desc
iSortingCols: 2
並使用php中的GET參數來處理請求。 然后我需要向請求中添加更多參數,因此我將選項更改為
$('#tbl-kamus').DataTable({
"processing": true,
"bServerSide": true,
"ajax": {
"url": srcUri,
"data": {
"user_id": userID
}
...
整個請求參數變成了類似數組的東西:
draw: 1
columns[0][data]: 0
columns[0][name]:
columns[0][searchable]: true
columns[0][orderable]: false
columns[0][search][value]:
columns[0][search][regex]: false
columns[1][data]: 1
columns[1][name]:
columns[1][searchable]: true
columns[1][orderable]: true
columns[1][search][value]:
columns[1][search][regex]: false
columns[2][data]: 2
columns[2][name]:
columns[2][searchable]: true
columns[2][orderable]: true
columns[2][search][value]:
columns[2][search][regex]: false
columns[3][data]: 3
columns[3][name]:
columns[3][searchable]: true
columns[3][orderable]: false
columns[3][search][value]:
columns[3][search][regex]: false
order[0][column]: 1
order[0][dir]: desc
order[1][column]: 2
order[1][dir]: desc
start: 0
length: 30
search[value]:
search[regex]: false
user_id: 2
因此,我必須更改服務器端腳本以適應該情況,這是我避免的。 然后作為一種解決方法,我繼續使用sAjaxSource並將user_id附加到url中,如下所示:
"sAjaxSource":srcUri+"?user_id="+userID+"&",
令我困擾的是為什么它們具有不同的請求參數格式。 誰能解釋一下它們為什么不同以及每種方法之間的意義是什么?
編輯:
對不起,也許我的解釋不太清楚。 我在這里問的不是如何在數據表ajax中傳遞參數。 盡管我非常感謝fnServerParams的提及,但這是我需要的atm。
我在這里問的是,為什么sAjaxSource和ajax之間的請求參數如此不同? 還是兩種方法都有不同的用途? 我似乎在文檔中找不到它。
從文檔中 :
較早版本的DataTables(1.9-)使用一組不同的參數來從服務器發送和接收。 因此,為DataTables 1.10+編寫的腳本將無法與DataTables 1.9-一起使用。 但是,DataTables 1.10確實具有針對1.9-編寫的腳本的兼容模式。 通過使用舊的sAjaxSource參數(而不是新的ajax參數)或通過設置$ .fn.dataTable.ext.legacy.ajax = true觸發此兼容模式。
當將sAjaxSource與DataTables(1.10+)一起使用時,您將觸發兼容模式,該表發送和接收的參數集與舊版DataTables(1.9-)不同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.