datatables ajax json,javascript - jquery Datatables using JSON - Stack Overflow

博主在尝试使用jQuery DataTables插件展示从PHP通过AJAX获取的JSON数据,但只希望显示'id','name'和'account_name'三列。目前遇到困难,代码中存在错误导致无法正常显示。错误信息未给出,需要解决DataTable的数据绑定问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am using datatables jQuery plugin to show the data nicely withing a table. I am making an ajax request on a click of a button which is then running a php script returning a JSON.

Here's how my code:

$('#searchInSugar').button().on('click', function (e) {

var searchTxt = $('#searchEntry').val();

var moduleName = $('#moduleSelect').val();

if (!searchTxt.trim() || searchTxt.length === 0) {

alert("Please provide some search text string..");

return false;

}

if (moduleName === "select") {

alert("Please select a module..");

return false;

}

$.ajax({

type: 'POST',

url: "fetch_records.php",

data: {"searchText": searchTxt,

"module": moduleName},

success: function (data) {

obj = JSON.parse(data);

$(document).ready(function () {

$('#dialog_entry_table').DataTable({

"info": false,

data: data,

columns: [

{"records": "id"},

{"records": "name"},

{"records": "account_name"}

]

});

});

},

error: function (exception) {

alert('Exeption:' + exception);

}

});

});

Here's the json that I get from the php script.

{

"next_offset":-1,

"records":[

{

"id":"a54e81f8-72b2-ae9b-d526-5608761a28e8",

"name":"Mr. James Smith",

"date_modified":"2015-09-27T23:52:29+00:00",

"account_name":"",

"_acl":{

"fields":{

}

},

"_module":"Contacts"

},

{

"id":"b8ec2e0a-ade1-f70f-d722-56098e5c4370",

"name":"james bond",

"date_modified":"2015-09-28T22:50:56+00:00",

"account_name":"",

"_acl":{

"fields":{

}

},

"_module":"Contacts"

},

{

"id":"4de93888-155c-7e59-9c4b-56058f1b7ce9",

"name":"Mr. James Bond",

"date_modified":"2015-09-28T01:50:49+00:00",

"account_name":"OSSG",

"_acl":{

"fields":{

}

},

"_module":"Contacts"

}

]

}

Now, I ONLY WANT TO SHOW id, name and account_name IN THE TABLE, But I am having a hard time achieving this, could someone help/advise what I am doing wrong here.

This is the error I am getting:

X2nw6.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值