数据类型TypeError:c未定义 [英] Datatables TypeError: c is undefined
问题描述
我尝试使用jQuery DataTables,但是我收到错误
TypeError:c is undefined
我不知道我的代码有什么问题,因为我可以看到JSON正确检索,并且格式正确,但我不知道是什么问题我得到上述错误。
我的JSON:
{Data:[{LOGIN:10184},{LOGIN:10214},{LOGIN:10180},{LOGIN:10187},{LOGIN:10179},{LOGIN :10280},{LOGIN:201},{LOGIN:10238},{LOGIN:10296},{LOGIN:10312}]}
pre>
和我的DataTables代码:
$(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});},
cont entType: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,
列:[
{data:LOGIN}
]
});
});
解决方案
dataSrc
是一个特殊的dataTables选项,应该包含在ajax对象内:ajax:{
dataSrc:Data,//< ---将dataSrc这里替换为
type:POST,
...
}
你把它放在ajax和dataTable之外不知道使用什么源码(除了盲目尝试ajax响应)还是
LOGIN
所在的位置。I try to use jQuery DataTables but I get the error
TypeError: c is undefined
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.
My JSON :
{"Data":[{"LOGIN":10184},{"LOGIN":10214},{"LOGIN":10180},{"LOGIN":10187},{"LOGIN":10179},{"LOGIN":10280},{"LOGIN":201},{"LOGIN":10238},{"LOGIN":10296},{"LOGIN":10312}]}
and my DataTables code:
$(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
is a special dataTables ajax option, that should be included inside the ajax object :"ajax": { "dataSrc": "Data", //<--- place dataSrc here instead "type": "POST", ... }
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.这篇关于数据类型TypeError:c未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!