首页 > 解决方案 > DataTables 不能使用 JSON

问题描述

我开始在我的 Codeigniter 项目中使用 DataTable,但我无法使用 JSON 获取数据:如您所见,这是我的 Javascript 代码和下面给出的 JSON 数据结构:

$('#sms_tab').DataTable({
    "ajax" : "http://localhost/p/contact/sms",
    "columns" : [
        {"result" : "texto_id"},
        {"result" : "texto_body"},
        {"result" : "texto_date"},
        {"result" : "texto_time"},
        {"result" : "texto_type"},
        {"result" : "state"}
    ]
});

JSON数据结构:

{
    "site":"http:\/\/localhost\/p\/",
    "page":"contact\/sms",
    "jsFunction":"sms",
    "baseurl":"http:\/\/localhost\/p\/",
    "result":[{
        "texto_id":"1",
        "texto_body":"hello world",
        "texto_date":"2018-08-01",
        "texto_time":"04:27:07",
        "related_contacts":"1",
        "related_users":"1",
        "texto_type":"OUT",
        "state":"1"
    },
    {
        "texto_id":"2",
        "texto_body":"test",
        "texto_date":"2018-08-09",
        "texto_time":"05:18:22",
        "related_contacts":"1",
        "related_users":"1",
        "texto_type":"IN",
        "state":"1"
    },
    {
        "texto_id":"3",
        "texto_body":"hhhh",
        "texto_date":"2018-08-09",
        "texto_time":"10:28:10",
        "related_contacts":"1",
        "related_users":"1",
        "texto_type":"OUT",
        "state":"1"
    },

标签: javascriptphpdatatable

解决方案


推荐阅读