0

我已经使用 Datatables 一段时间了,在同一个网站上,我有两个单独的页面使用它。一个有效,一个给我标题中的 JSON 错误。奇怪的是,我从工作页面复制并粘贴了代码以创建非工作页面,并且响应看起来都有效。

JSON响应(显然很糟糕......我觉得很好):

{"sEcho":0,"iTotalRecords":"190","iTotalDisplayRecords":"2","aaData":[["4","1","1","2","0"], ["91","2","1","1","0"]]}

4

1 回答 1

0

我发现我的错误...

我在 mySQL SELECT 查询中使用了“AS”。显然这会阻止 Datatables 正确解析响应,即使它看起来正确。

坏的:

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> &nbsp;", 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

好的:

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> &nbsp;", 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
于 2012-08-18T22:41:36.307 回答