gpt4 book ai didi

javascript - 数据未加载到数据表中

转载 作者:行者123 更新时间:2023-11-30 14:24:13 25 4
gpt4 key购买 nike

我使用以下代码使用 ajax 加载数据表。数据未加载到数据库中,

$('#new_table').DataTable({
"processing": true,
"serverSide": true,
"ajax":{
"url": "<?php echo base_url();?>index.php/Members/membergetajax",
"dataType": "json",
"type": "POST",
"dataSrc": "",
},
"lengthMenu": [5, 10, 20, 50, 100],
"pageLength": 5,
"columnDefs": [{
"className": "dt-center", "targets": 0
},{
"className": "dt-center", "targets": 1
},{
"className": "dt-center", "targets": 2
}],
"columns": [
{ "data": "id"},
{ "data": "first_name" },
{ "data": "member_id" }
]
});

ajax的数据格式

 "data":[
{"id":"1","first_name":"Arun","member_id":"Mem01"},
{"id":"2","first_name":"Dinesh","member_id":" Mem02 "},
{"id":"3","first_name":"Ramesh ","member_id":"Mem03 "},
{"id":"4","first_name":"Mahesh ","member_id":"Mem04 "},
{"id":"5","first_name":"Rajesh ","member_id":"Mem05"}
]

请帮我找出问题,提前致谢

最佳答案

根据documentation你有两种可能性:

  • dataSrc设置为data -->"dataSrc": "data"
  • 您的 ajax 调用应该只返回数据值:

    [{
    "id": "1",
    "first_name": "Arun",
    "member_id": "Mem01"
    }, {
    "id": "2",
    "first_name": "Dinesh",
    "member_id": " Mem02 "
    }, {
    "id": "3",
    "first_name": "Ramesh ",
    "member_id": "Mem03 "
    }, {
    "id": "4",
    "first_name": "Mahesh ",
    "member_id": "Mem04 "
    }, {
    "id": "5",
    "first_name": "Rajesh ",
    "member_id": "Mem05"
    }]

关于javascript - 数据未加载到数据表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52203714/

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