所以我环顾四周,找不到任何人现在遇到的问题。我使用Jquery Datatables并使用JSON填充此数据表我从ajax调用中接收。我一直得到tn 4错误,这意味着我有一个未知参数。 https://www.datatables.net/manual/tech-notes/4。但我不明白为什么会这样!我将尝试尽可能详细地说明是否有人可以帮助我解决这个恼人的问题!
这是我收到的确切错误代码。
DataTables警告:table id = manageUsersTable - 请求的未知参数' CONCAT(E.FNAME,'',E.LNAME)'对于第0行。有关此错误的详细信息,请参阅http://datatables.net/tn.4
这是我的PHP查询:
$result = $conn->query("SELECT CONCAT(E.FNAME, ' ', E.LNAME), CONCAT(M.FNAME, ' ', M.LNAME), E.ISTERMINATED FROM EMPLOYEE E INNER JOIN EMPLOYEE M ON M.ID = E.SUPERVISOR;")
这是初始化数据表的javasript:
manageUsersTable = $('#manageUsersTable').dataTable({
"responsive": true,
"sAjaxDataProp": "",
"sAjaxSource": "all_emps.php",
"aoColumns":[
{ "mData": "CONCAT(E.FNAME, ' ', E.LNAME)"},
{ "mData": "CONCAT(M.FNAME, ' ', M.LNAME)"},
{ "mData": "ISTERMINATED"}
]
});
$('#manageUsersTable tbody').on( 'click', 'tr', function () {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
}
else {
manageUsersTable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
我有一个ajax调用,用于通过执行console.log查看数据,这是该调用。
$.ajax({ url: 'all_emps.php',
type: 'post',
success: function(data){
console.log(data);
}
});
这是我看到的JSON值:
[{"CONCAT(E.FNAME, ' ', E.LNAME)":"John Paul","CONCAT(M.FNAME, ' ', M.LNAME)":"Bob Saget","ISTERMINATED":"Employed"},{"CONCAT(E.FNAME, ' ', E.LNAME)":"Jim Bob","CONCAT(M.FNAME, ' ', M.LNAME)":"Bob Saget","ISTERMINATED":"Employed"},{"CONCAT(E.FNAME, ' ', E.LNAME)":"Saget Bob","CONCAT(M.FNAME, ' ', M.LNAME)":"Bobbity Saget","ISTERMINATED":"Employed"},{"CONCAT(E.FNAME, ' ', E.LNAME)":"Sagetty Bob","CONCAT(M.FNAME, ' ', M.LNAME)":"Bob Sagetry","ISTERMINATED":"Employed"},{"CONCAT(E.FNAME, ' ', E.LNAME)":"Sagetry Bob","CONCAT(M.FNAME, ' ', M.LNAME)":"Wilbur Wright","ISTERMINATED":"Employed"}]
答案 0 :(得分:1)
使用别名代替数据库函数字段
$result = $conn->query("SELECT CONCAT(E.FNAME, ' ', E.LNAME) as ENAME, CONCAT(M.FNAME, ' ', M.LNAME) as MNAME, E.ISTERMINATED FROM EMPLOYEE E INNER JOIN EMPLOYEE M ON M.ID = E.SUPERVISOR;")
并在数据表列defs中使用这些名称
"aoColumns":[
{ "mData": "ENAME"},
{ "mData": "MNAME"},
{ "mData": "ISTERMINATED"}
]
答案 1 :(得分:0)
尝试别名CONCAT()语句。
SELECT CONCAT(E.FNAME, ' ', E.LNAME) AS name1, etc...