DataTables warning: table id=participant - Invalid JSON response.

DataTables warning: table id=participant - Invalid JSON response.

bpmspacebpmspace Posts: 17Questions: 5Answers: 0

HI

no clue why my response from the server shall not be vaild JSON -

I try to implement https://datatables.net/manual/server-side with 10 preloaded rows
every time i try to search or set pagination from 25 to 100 I get

DataTables warning: table id=participant - Invalid JSON response. 

But i verified the json answer - it is json to me ! and also to https://jsonlint.com/
Any hints?
Thanks rob

Here is my html

        <html lang="en">       <head>

...

            </head>
            <body>

....

....
Action ID Lastname Fristname Mail date of birthstate
96645546482 male DE Griffin Daniel Griffin.Daniel@jlbba.google.com 03-12-1987complete

....

.... $(document).ready(function() { $('#participant').DataTable({ "processing": true, "serverSide": true, "ajax": "/api/Particicpant_ServerSide.php", "deferLoading": 100, "search": { search: "", }, columnDefs: [ { orderable: false, targets: 0 }, { orderable: false, targets: 8 } ], "order": [[ 1, "desc" ]], "pageLength": 10 } ); }); ...

</body>
</html>

Here is the answer (Anonymized data) from the server (limit)

{"draw":0,"recordsTotal":40,"recordsFiltered":40,"data":[["action","116482","male","DE","Griffin","Daniel","Griffin.Daniel@jlbba.google.com","03-12-1987","status","action_status"],["action","116481","male","DE","Cooper","John","Cooper.John@ruzot.google.com","23-02-1993","status","action_status"],["action","116480","female","DE","Washington","Maria","Washington.Maria@isrew.mail.com","12-04-1989","status","action_status"],["action","116479","female","DE","Gonzalez","Joseph","Gonzalez.Joseph@nmtkr.yahoo.com","21-01-1991","status","action_status"],["action","116478","male","DE","Gray","Joshua","Gray.Joshua@gyyxr.live.com","13-08-1993","status","action_status"],["action","116477","female","DE","Reed","Edward","Reed.Edward@vxbpu.google.com","19-01-1980","status","action_status"],["action","116476","male","DE","Cox","Maria","Cox.Maria@cceoh.live.com","23-12-1977","status","action_status"],["action","116475","male","DE","Nelson","Donna","Nelson.Donna@jsmeo.google.com","08-11-1975","status","action_status"],["action","116474","male","DE","Rivera","Ruth","Rivera.Ruth@silgz.google.com","19-11-1985","status","action_status"],["action","116473","male","DE","Smith","Barbara","Smith.Barbara@gqkfv.yahoo.com","22-08-1979","status","action_status"],["action","116472","male","DE","Williams","Henry","Williams.Henry@emuol.live.com","20-06-1988","status","action_status"], ...

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Yep, I agree, that JSON looks good. It doesn't look like a valid response though, as the draw should match what was sent in the request. The first request would be 1, so 0 looks suspiscious.

    If that doesn't resolve the problem, could you link to your page so we can take a look, please.

    Colin

  • bpmspacebpmspace Posts: 17Questions: 5Answers: 0

    Hi Colin
    thanks - since it is a test system you can have acess

    https://comsii.bpmspace.net/index.php?target=participant_grid

    user: Colin
    paaswd: Colin9843756983

    https://comsii.bpmspace.net/api/Particicpant_ServerSide.php

    Thanks rob

  • kthorngrenkthorngren Posts: 21,181Questions: 26Answers: 4,924

    Looking at the browser's network inspector I see the following response:

    <br />
    <b>Warning</b>:  htmlspecialchars() expects parameter 1 to be string, array given in <b>/var/www/html/inc/config.db.inc.php</b> on line <b>18</b><br />
    <br />
    <b>Warning</b>:  htmlspecialchars() expects parameter 1 to be string, array given in <b>/var/www/html/inc/config.db.inc.php</b> on line <b>18</b><br />
    <br />
    <b>Warning</b>:  htmlspecialchars() expects parameter 1 to be string, array given in <b>/var/www/html/inc/config.db.inc.php</b> on line <b>18</b><br />
    {"draw":2,"recordsTotal":40,"recordsFiltered":40,"data":[["action","116482","male","deutsch","Griffin","Daniel","Griffin.Daniel@jlbba.google.com","03-12-1987","status","action_status"],["action","116481","male","deutsch","Cooper","John","Cooper.John@ruzot.google.com","23-02-1993","status","action_status"],["action","116480","female","deutsch","Washington","Maria","Washington.Maria@isrew.mail.com","12-04-1989","status","action_status"],["action","116479","female","deutsch","Gonzalez","Joseph","Gonzalez.Joseph@nmtkr.yahoo.com","21-01-1991","status","action_status"],["action","116478","male","deutsch","Gray","Joshua","Gray.Joshua@gyyxr.live.com","13-08-1993","status","action_status"],["action","116477","female","deutsch","Reed","Edward","Reed.Edward@vxbpu.google.com","19-01-1980","status","action_status"],["action","116476","male","deutsch","Cox","Maria","Cox.Maria@cceoh.live.com","23-12-1977","status","action_status"],["action","116475","male","deutsch","Nelson","Donna","Nelson.Donna@jsmeo.google.com","08-11-1975","status","action_status"],["action","116474","male","deutsch","Rivera","Ruth","Rivera.Ruth@silgz.google.com","19-11-1985","status","action_status"],["action","116473","male","deutsch","Smith","Barbara","Smith.Barbara@gqkfv.yahoo.com","22-08-1979","status","action_status"]]}
    

    There are extra lines at the top causing the error. Looks like the response you show with draw: 0 is from this link directly:
    https://comsii.bpmspace.net/api/Particicpant_ServerSide.php

    So its not seeing the parameters sent by Datatables and not generating the errors above. For troubleshooting its better to use the browser's network inspector to see the actual response.

    Not sure why your server script is generating those errors.

    Kevin

  • bpmspacebpmspace Posts: 17Questions: 5Answers: 0
    edited April 2021

  • bpmspacebpmspace Posts: 17Questions: 5Answers: 0
    edited April 2021

    $sql_details is set in an config file

  • bpmspacebpmspace Posts: 17Questions: 5Answers: 0

    the example also starts with {"draw": ....

  • kthorngrenkthorngren Posts: 21,181Questions: 26Answers: 4,924
    Answer ✓

    With server die processing enabled the draw and other parameters you see are expected. Please see the server side processing protocol docs for more details.

    The problem is with lines 1 - 6 in the output I posted above. You will need to troubleshoot your server script to find out why its returning those lines and remove them.

    Kevin

  • bpmspacebpmspace Posts: 17Questions: 5Answers: 0

    OK - got it! - working! - Thank you rob

This discussion has been closed.