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

别等时光非礼了梦想. 提交于 2020-01-21 18:51:08

问题


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 be parsed. This is Caused by a JSON formatting error.

I found some suggestions in the forums but nothing has worked for me

Anyone have any suggestions?


回答1:


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




回答2:


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

[["row1col1","row1col2"],["row2col1"],.....]



回答3:


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




回答4:


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" }
        ]
    });



回答5:


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" );


来源:https://stackoverflow.com/questions/8330746/datatables-warning-json-data-from-server-could-not-be-parsed-this-is-caused-by

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!