DataTables警告:无法解析来自服务器的JSON数据。 这是由JSON格式错误引起的

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?

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

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

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

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

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

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