DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error

前端 未结 5 1714
太阳男子
太阳男子 2021-01-23 08:27

I am using server-side DataTables in a project

and do a search, shows me the following error message:

DataTables warning: JSON data from server not could b

相关标签:
5条回答
  • 2021-01-23 08:33

    If you are using :

    "sAjaxSource": "myHandler.php"
    

    Then you mus return from your handler:

    "{\"aaData\": [{\"propOne\": \"valueOne\"},{\"propTwo\": \"valueTwo\"}], [...],... }"
    

    Note

    \"aaData\":
    

    before json collection and note brakects:

    {\"aaData\"....}
    

    My example in asp.net(this is working):

    Response.Write("{\"aaData\": [{\"propOne\": \"valueOne\"},{\"propTwo\": \"valueTwo\"}]}");
    

    Client page:

          oTable = $('#myTable').dataTable( {
            "bProcessing": true,
            "sPaginationType": "full_numbers",
            "aLengthMenu": [[5,10,20,50,100], [5,10,20,50,100]],
            "aaSorting": [[ 1, "desc" ]],
            "sAjaxSource": "MyHandler.ashx",
            "aoColumns": [
                { "mDataProp": "propOne" },
                { "mDataProp": "propTwo" }
            ]
        });
    
    0 讨论(0)
  • 2021-01-23 08:34

    For newer versions of datatables,don't forget to remove this line from the server_processing.php file

    /* REMOVE THIS LINE (it just includes my SQL connection user/pass) */
        include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" );
    
    0 讨论(0)
  • 2021-01-23 08:45

    check the network tab in firebug, you would probably see the underlying server error

    0 讨论(0)
  • 2021-01-23 08:45

    You're json is not in the valid format which datatables expects, that being row/column 2d array.

    [["row1col1","row1col2"],["row2col1"],.....]
    
    0 讨论(0)
  • 2021-01-23 08:45

    I ran into this problem and it was as simple as updating the information in the following file:

        "sAjaxSource": "DataTables/examples/server_side/scripts/server_processing.php"
    

    Don't know if the answer you're looking for is that pedestrian, but I figured I would throw in my 2 cents!!

    0 讨论(0)
提交回复
热议问题