我如何使用jquery.ajax语法和codeigniter正确管理数据表?我想使用我自己的语法:
$.ajax({
url: url,
})
我希望有人可以帮助我,或者给我一些代码来宣传。
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "scripts/post.php",
"type": "POST"
},
"columns": [
{ "data": "first_name" },
{ "data": "last_name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
答案 0 :(得分:1)
与DataTables init分开执行AJAX查询:
进行AJAX调用并将结果存储在对象中,然后将对象传递给启动表的函数:
var obj = {};
$.ajax({
// your ajax parameters
}).success(function (data) {
obj = JSON.parse(data.d);
//..perhaps verify obj has results before passing to dataToTable function
dataToTable(obj);
});
dataToTable函数类似于:
function dataToTable(dataSet) {
$('#example').DataTable({
"data": dataSet,
//..your other datatables settings
});
}
答案 1 :(得分:0)
你可以试试这个:
$('#table_id').dataTable({
"sServerMethod": "GET",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/post.php", // codeigniter method url("scripts/get_data")
"aoColumns": [ { "bSortable": true }, { "bSortable": false }, { "bSortable": true }, { "bSortable": false }],
});
其中sAjaxSource就像ajax的url参数。