我正在爲DataTables編寫服務器端處理代碼。我有一個UI頁面,我收集所有用戶輸入,如開始/結束日期,令牌ID,批次ID等。現在我必須將這些值傳遞給後端腳本,並在UI頁面中運行查詢並將輸出呈現給數據表。DataTables服務器端腳本的客戶端腳本
所以我有JS代碼來接受和驗證用戶輸入,但我不知道如何調用/設置數據表的params來狀態服務器端腳本。以下是我的腳本:
function runreport(datastring)
{
var oTable = $('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "runsearch.py",
"bDestroy" : true,
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": function(json) {
$("div#report_result").show();
$('html, body').animate({scrollTop:$(document).height()}, 'slow');
fnCallback(json);
}
});
}
});
}
當所有輸入參數都被驗證時,我調用'runreport'方法。我構造datastring就像查詢字符串:token_id = xxxx & [email protected] & start_date = 1212121212 & end_date = 98989898但這些值不被傳遞?我得到以下錯誤:
k is undefined
[Break On This Error]
...Sorting=="undefined"&&typeof e.saved_aaSorting=="undefined")e.aaSorting[a][1]=k....
jquery....min.js (line 150)
我們應該怎麼做才能讓DataTables結果從後端腳本生成?
我沒有得到所需的結果輸出?這是調用服務器端processg的DataTables功能的正確方法嗎?
下面是我的Python代碼轉儲靜態結果集:
#!/usr/local/bin/python
import cgi
import MySQLdb
import json
print "Content-Type: application/json"
print
displaylength =5
result = {'iDisplayLength':str(displaylength), 'sPaginationType':'full_numbers', 'bProcessing':1, 'bDestroy': 1, 'bRetrieve':1, 'aaData':[{'First Field':'First Field Value', 'Second Field':'Second Field Value', 'Third Field':'Third Field Value', 'Fourth Field':'Fourth Field Value', 'Fifth Field':'Fifth Field Value', 'Sixth Field':'Sixth Field Value', 'Seventh Field':'Seventh Field Value', 'Eight Field':'Eight Field Value', 'Nineth Field':'Nineth Field Value'}, {'First Field':'First Field Value', 'Second Field':'Second Field Value', 'Third Field':'Third Field Value', 'Fourth Field':'Fourth Field Value', 'Fifth Field':'Fifth Field Value', 'Sixth Field':'Sixth Field Value', 'Seventh Field':'Seventh Field Value', 'Eight Field':'Eight Field Value', 'Nineth Field':'Nineth Field Value'}], 'aoColumns':[{'sTitle':'First Field', 'mDataProp': 'First Field'},{ 'sTitle':'Second Field', 'mDataProp': 'Second Field'}, {'sTitle':'Third Field', 'mDataProp': 'Third Field' }, { 'sTitle':'Fourth Field', 'mDataProp': 'Fourth Field' }, { 'sTitle':'Fifth Field' , 'mDataProp': 'Fifth Field' }, { 'sTitle':'Sixth Field', 'mDataProp': 'Sixth Field' }, { 'sTitle':'Seventh Field', 'mDataProp': 'Seventh Field' }, { 'sTitle':'Eight Field', 'mDataProp': 'Eight Field' }, { 'sTitle':'Nineth Field', 'mDataProp': 'Nineth Field' }]}
json_string = json.dumps(result)
print json_string
http://datatables.net/usage/#data_sources是的,我想使用服務器端處理,並想知道我的腳本有什麼問題? – Prakash
你在用什麼語言編寫服務器端腳本?請分享該代碼。如果我看不到代碼,我不知道問題出在哪裏。 –
我已經添加了用Python編寫的後端代碼 – Prakash