gpt4 book ai didi

codeigniter - 带有 Ignited-Datatables CodeIgniter 的 Jquery DataTable

转载 作者:行者123 更新时间:2023-12-04 05:40:12 25 4
gpt4 key购买 nike

更新:

I finally found the solution for this problem. If you face the same problem as mine, you can try visit this link



我想将 Jquery DataTablesCodeIgniter Ignited-Datatables 库集成时遇到问题

当我使用默认的 DataTables sServerMethod 属性“GET”时,我从我的 php.ini 文件中得到了带有数据的 json 响应。但是,由于 CodeIgniter 使用 post,尽管该函数返回了正确的 json 输出,但我仍然坚持加载服务器数据。

enter image description here

所以我按照这个 guide sServerMethod 更改为“POST”。现在我不再坚持加载服务器数据,但我没有得到我需要的数据。

使用 sServerMethod GET 的 JSON 响应(获取正确的 json,但卡在加载服务器数据时,如图所示)
{
"sEcho": 0,
"iTotalRecords": 10,
"iTotalDisplayRecords": 10,
"aaData": [
[
"Munauwar",
"Syed",
"Mr",
"6012345678",
"0000-00-00",
"basikal"
],
[
"Mak",
"Je Wei",
"Mr",
"6012345678",
"0000-00-00",
"motor"
]
],
"sColumns": "first_name,last_name,salutation,number,birthday,group_name"}

JSON 响应使用 sServerMethod POST
{
"sEcho": 1,
"iTotalRecords": 10,
"iTotalDisplayRecords": 0,
"aaData": [],
"sColumns": "first_name,last_name,salutation,number,birthday,group_name"}

这是我的 javascript 代码
$('#table1').dataTable({
"bProcessing": true,
"bServerSide": true,
"sPaginationType": "bootstrap",
"sAjaxSource": config.base_url + "contact/popup_contact",
"sServerMethod": "POST"

});

我在接触 Controller 中的功能
function popup_contact()
{
$this->datatables
->select('first_name,last_name,salutation,number,birthday,group_name')
->from('tb_contact')
->join('tb_contact_group', 'tb_contact.contact_group_id = tb_contact_group.contact_group_id');

echo $this->datatables->generate();

}

最佳答案

如果上面的方法还是不行,那是因为你设置了: $config['csrf_protection'] = true;//在你的 Codeigniter 配置中

只需在 fnServerData 调用中添加 aoData.push 行:

"fnServerData": function(sSource, aoData, fnCallback) {
aoData.push({name: '<?php echo $this->security->get_csrf_token_name(); ?>', value: '<?php echo $this->security->get_csrf_hash(); ?>'});
$.ajax({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': fnCallback
});
}

关于codeigniter - 带有 Ignited-Datatables CodeIgniter 的 Jquery DataTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11355542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com