How to solve JSON parse error: Unrecognized token issue in datatables?

How to solve JSON parse error: Unrecognized token issue in datatables?

mastersusemastersuse Posts: 61Questions: 28Answers: 0

I got this error at browser response.

{"timestamp":"2020-05-19T05:39:22.351+0000","status":400,"error":"Bad Request","message":"JSON parse error: Unrecognized token 'uid': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'uid': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (PushbackInputStream); line: 1, column: 5]","path":"/api/v1/test"}

Error: JSON parse error: Unrecognized token

How to solve it?

I got success when using postman

Below is my datatables code

$('#userTable').DataTable({ 
    serverSide: true,
    ajax: { 
        url: api_url + '/api/v1/test',
        crossDomain : true,
        type : "POST",
        cache : false,
        dataType : "json",
        contentType: "application/json",
        dataSrc : "user",
        data: {
            "uid": "X123",
            "tokenid": "aasdkajf2324",
            "item": "user",
            "action": "read",
            "type": "1",
            "keyword": ""
        }
    },
    columns: [
        { data : "full_name", "className": "text-center" },
        { data : "userid", "className": "text-center" },
        { data : "level", "className": "text-center" }
    ],
});

Answers

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    First thing I'd say is to remove serverSide: true, since it doean't appear that you are actually using server-side processing (indeed, the Postman parameters don't include those that would have been sent by DataTables - the difference between client-side and server-side processing is discussed in the manual).

    Beyond that - I'm not certain. Can you link to the page or a test case showing the issue so we can help resolve it please?

    Thanks,
    Allan

  • mastersusemastersuse Posts: 61Questions: 28Answers: 0

    I just get the solution by this way

    ```JS
    data: function(d) {
    return JSON.stringify({"uid": "X123", "tokenid": "asdq4234", "item": "user", "action": "read", "type": "1", "keyword": "" });
    }
    ``

This discussion has been closed.