我正在为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