我已经使用了Datatables一段时间了,在同一个网站上,我有两个单独的页面使用它。一个工作,一个给我标题中的JSON错误。奇怪的是,我复制并粘贴了工作页面中的代码以创建无效页面,并且响应看起来都是有效的。
JSON回应(显然不好......看起来很精致):
{ “sEcho”:0 “iTotalRecords”: “190”, “iTotalDisplayRecords”: “2”, “aaData”:[[ “4”, “1”, “1”, “2”,“0 “],[” 91" , “2”, “1”, “1”, “0”]]}
答案 0 :(得分:0)
我发现了我的错误......
我在mySQL SELECT查询中使用“AS”。显然,这会阻止Datatables正确解析响应,即使它看起来是正确的。
BAD:
SELECT SQL_CALC_FOUND_ROWS concat( "<input type='hidden' id='task_code' value='", t.id, "'><a href='learningguide_edit.php?task=", lg.taskID, "'><img src='../img/view_details_icon.gif' border='0'></a> ", t.title ) AS task, IF(lg.cc_standards<>'-1',LENGTH(REPLACE(lg.cc_standards, '|', '@@'))-LENGTH(lg.cc_standards)+1,0) AS CC_Count, IF(lg.state_standards<>'-1',LENGTH(REPLACE(lg.state_standards, '|', '@@'))-LENGTH(lg.state_standards)+1,0) AS State_count, IF(lg.nocti_standards<>'-1',LENGTH(REPLACE(lg.nocti_standards, '|', '@@'))-LENGTH(lg.nocti_standards)+1,0) AS NOCTI_count, IF(lg.industry_standards<>'-1',LENGTH(REPLACE(lg.industry_standards, '|', '@@'))-LENGTH(lg.industry_standards)+1,0) AS Ind_count
FROM mlg_learning_guides lg, mlg_tasklist_5 t
WHERE lg.taskID=t.id AND lg.courseID=5
GOOD:
SELECT SQL_CALC_FOUND_ROWS concat( "<input type='hidden' id='task_code' value='", t.id, "'><a href='learningguide_edit.php?task=", lg.taskID, "'><img src='../img/view_details_icon.gif' border='0'></a> ", t.title ), IF(lg.cc_standards<>'-1',LENGTH(REPLACE(lg.cc_standards, '|', '@@'))-LENGTH(lg.cc_standards)+1,0), IF(lg.state_standards<>'-1',LENGTH(REPLACE(lg.state_standards, '|', '@@'))-LENGTH(lg.state_standards)+1,0), IF(lg.nocti_standards<>'-1',LENGTH(REPLACE(lg.nocti_standards, '|', '@@'))-LENGTH(lg.nocti_standards)+1,0), IF(lg.industry_standards<>'-1',LENGTH(REPLACE(lg.industry_standards, '|', '@@'))-LENGTH(lg.industry_standards)+1,0)
FROM mlg_learning_guides lg, mlg_tasklist_5 t
WHERE lg.taskID=t.id AND lg.courseID=5