Invalid JSON response with JSON data validated by JSONLint

Invalid JSON response with JSON data validated by JSONLint

syneausyneau Posts: 4Questions: 1Answers: 0

Hi,

I'm trying to get data from mysql db on a server.

I trid server-side, with JSON or JSONP method.

I get : DataTables warning: table id=tableDico - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

The i validate my data with JSONLite :
{
"draw": 1,
"recordsTotal": 858694,
"recordsFiltered": 858694,
"data": [
["04-DAT", "A8", "8", "", "", "Variable Groupe", "01", "SBK0", "IN", "I4RN60"],
["04-JJ", "N2", "2", "99", "", "Variable Elementaire", "03", "SBK0", "IN", "I4RN60"],
["04-MM", "N2", "2", "99", "", "Variable Elementaire", "03", "SBK0", "IN", "I4RN60"],
["04-SSAA", "N4", "4", "9(4)", "", "Variable Elementaire", "03", "SBK0", "IN", "I4RN60"],
["1-ENTR-MAXI", "A2036", "2036", "", "", "Variable Groupe", "01", "SBK0", "AD", "A0DD51"],
["1-ENTR-MINI", "A2", "2", "", "", "Variable Groupe", "01", "SBK0", "AD", "A0DD51"],
["1-ENTR1", "A37", "37", "", "", "Variable Groupe", "01", "SBK0", "AD", "A0DD51"],
["1-ENTR1-COD-EMET", "A4", "4", "X(4)", "", "Variable Elementaire", "02", "SBK0", "AD", "A0DD51"],
["1-ENTR1-DAT-CRE", "N8", "8", "9(8)", "", "Variable Elementaire", "02", "SBK0", "AD", "A0DD51"],
["1-ENTR1-DAT-DEB", "N8", "8", "9(8)", "", "Variable Elementaire", "02", "SBK0", "AD", "A0DD51"]
]
}

I used the debug tool :
with JSON : http://debug.datatables.net/arucaq
with JSONP : http://debug.datatables.net/egalut

The xhr response is (for JSON) :

SELECT SQL_CALC_FOUND_ROWS variable, dataflor, longphy, picture, usage, type, niveau, mode, GT, programme
FROM varhorscopy

         ORDER BY `variable` ASC
         LIMIT 0, 10SELECT FOUND_ROWS()SELECT COUNT(`idvarhorscopy`)
         FROM   `varhorscopy`{"draw":1,"recordsTotal":858694,"recordsFiltered":858694,"data":[["04-DAT","A8","8","","","Variable Groupe","01","SBK0","IN","I4RN60"],["04-JJ","N2","2","99","","Variable Elementaire","03","SBK0","IN","I4RN60"],["04-MM","N2","2","99","","Variable Elementaire","03","SBK0","IN","I4RN60"],["04-SSAA","N4","4","9(4)","","Variable Elementaire","03","SBK0","IN","I4RN60"],["1-ENTR-MAXI","A2036","2036","","","Variable Groupe","01","SBK0","AD","A0DD51"],["1-ENTR-MINI","A2","2","","","Variable Groupe","01","SBK0","AD","A0DD51"],["1-ENTR1","A37","37","","","Variable Groupe","01","SBK0","AD","A0DD51"],["1-ENTR1-COD-EMET","A4","4","X(4)","","Variable Elementaire","02","SBK0","AD","A0DD51"],["1-ENTR1-DAT-CRE","N8","8","9(8)","","Variable Elementaire","02","SBK0","AD","A0DD51"],["1-ENTR1-DAT-DEB","N8","8","9(8)","","Variable Elementaire","02","SBK0","AD","A0DD51"]]}

The xhr response is (for JSONP) :

SELECT SQL_CALC_FOUND_ROWS variable, dataflor, longphy, picture, usage, type, niveau, mode, GT, programme
FROM varhorscopy

         ORDER BY `variable` ASC
         LIMIT 0, 10SELECT FOUND_ROWS()SELECT COUNT(`idvarhorscopy`)
         FROM   `varhorscopy`jQuery11220617156900585451_1459258427273({"draw":1,"recordsTotal":858694,"recordsFiltered":858694,"data":[["04-DAT","A8","8","","","Variable Groupe","01","SBK0","IN","I4RN60"],["04-JJ","N2","2","99","","Variable Elementaire","03","SBK0","IN","I4RN60"],["04-MM","N2","2","99","","Variable Elementaire","03","SBK0","IN","I4RN60"],["04-SSAA","N4","4","9(4)","","Variable Elementaire","03","SBK0","IN","I4RN60"],["1-ENTR-MAXI","A2036","2036","","","Variable Groupe","01","SBK0","AD","A0DD51"],["1-ENTR-MINI","A2","2","","","Variable Groupe","01","SBK0","AD","A0DD51"],["1-ENTR1","A37","37","","","Variable Groupe","01","SBK0","AD","A0DD51"],["1-ENTR1-COD-EMET","A4","4","X(4)","","Variable Elementaire","02","SBK0","AD","A0DD51"],["1-ENTR1-DAT-CRE","N8","8","9(8)","","Variable Elementaire","02","SBK0","AD","A0DD51"],["1-ENTR1-DAT-DEB","N8","8","9(8)","","Variable Elementaire","02","SBK0","AD","A0DD51"]]});

Could you help me please :)

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin
    Answer ✓

    http://debug.datatables.net/arucaq

    Click the "Tables" tab at the top, then find and click the "Server interaction" button. You'll see the response from the server and the fact that it is not valid JSON. It also contains an SQL statement.

    Allan

  • syneausyneau Posts: 4Questions: 1Answers: 0

    Hi allan, Thx for your quick response.

    You are right, but why I get those SQL Statement ?
    I'm using your ssp.class.php (cloned and modified to comment the first block).

  • syneausyneau Posts: 4Questions: 1Answers: 0

    HOooo, I've found.

    There is a "echo $sql;" statment in the static function sql_exec.

    When commented, I get my data !!

    Thx for your help Allan.

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin
    Answer ✓

    I can only presume that something, somewhere in the script is echoing them out.

    As you can see in the examples on this site, it doesn't happen there.

    Allan

  • syneausyneau Posts: 4Questions: 1Answers: 0

    Remove the "echo $sql;" solves my problem.

This discussion has been closed.