数据表类型错误:c 未定义 [英] Datatables TypeError: c is undefined

查看:24
本文介绍了数据表类型错误:c 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 jQuery DataTables,但出现错误

I try to use jQuery DataTables but I get the error

类型错误:c 未定义

我不知道我的代码有什么问题,因为我可以看到 JSON 正确检索并且格式也正确,但我不知道出现上述错误的原因是什么.

I don't know what is wrong with my code as I can see the JSON correctly retrieve and is in the correct format too but I don't know what is wrong with it that I get the above error.

我的 JSON :

{"Data":[{"LOGIN":10184},{"LOGIN":10214},{"LOGIN":10180},{"LOGIN":10187},{"LOGIN":10179},{"LOGIN":10280},{"LOGIN":201},{"LOGIN":10238},{"LOGIN":10296},{"LOGIN":10312}]}

和我的数据表代码:

$(document).ready(function() {
    $('#tablename').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "type": "POST",
        "url": "https://test.com/api/db/select",
        "data": function ( json ) {  return JSON.stringify( { "Sql": 12 } );},
        "contentType": "application/json; charset=utf-8",
        "dataType": "json",
        "processData": true,
            beforeSend : function(xhr){
                        var access_token = sessionStorage.getItem('access_token');
                        xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
            }
        },
        "dataSrc": "Data",
        "columns": [
            { "data": "LOGIN" }
        ]
    } );
} );

推荐答案

dataSrc 是一个特殊的 dataTables ajax 选项,应该包含在 ajax 对象中:

dataSrc is a special dataTables ajax option, that should be included inside the ajax object :

"ajax": {
    "dataSrc": "Data", //<--- place dataSrc here instead
    "type": "POST",
    ...
}

你已经把它放在 ajax 之外,因此 dataTables 不知道使用什么来源(除了盲目地尝试 ajax 响应)或 LOGIN 所属的位置.

You have placed it outside ajax, and by that dataTables have no idea what source to use (besides blindly trying the ajax response) or where LOGIN belongs.

这篇关于数据表类型错误:c 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆