0
votes

I've used Datatables for a while now and on the same website, I have two separate pages that use it. One works and one gives me the JSON error in the title. The odd part is that I copied and pasted the code from the working page to create the not-working page and the responses both look valid.

JSON RESPONSE (APPARENTLY BAD... LOOKS FINE TO ME):

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

1

1 Answers

0
votes

I found my mistake...

I was using "AS" in the mySQL SELECT query. Apparently that will prevent Datatables from parsing the response properly even though it looks correct.

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> &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

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> &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