How can I fix this?

How can I fix this?

SkMickySkMicky Posts: 7Questions: 2Answers: 0

JSON parse error: Unrecognized token 'draw': was expecting ('true', 'false' or 'null');

This question has an accepted answers - jump to answer

Answers

  • David@QuantumDavid@Quantum Posts: 36Questions: 4Answers: 2

    Hey @SkMicky we're going to need a little more info than that to be able to help you. Perhaps you may have passed a string where you should have passed a bool, maybe it's an issue in the database, but there's very little that can be worked out from just the error.
    Here's a link to the Debugger which may help you understand better the issue you are experiencing.

    Hope this helps,
    David

  • SkMickySkMicky Posts: 7Questions: 2Answers: 0

    This is my datatable initializing
    table = $('#rolesTable').DataTable({
    select: true,
    processing: true,
    serverSide: true,
    ajax:{
    "url": 'http://aaa.bbb.zz:8083/role/data',
    "type": 'POST',
    "dataType":'json',
    "contentType": "application/json;charset=UTF-8",
    "headers": {
    'Authorization': localStorage.getItem('token')
    }
    },
    columns: [
    {
    "ordering": false,
    "data": null,
    "className": "details-control",
    "defaultContent": ''
    },
    {"data": "id", "className": "id"},
    {"data": "name"},
    {"data": "description"}
    ],
    });

    And this is table in my html

    ID Name Description

    When I send this request I get the 400 error JSONParseException:Unrecognized token 'draw'. I don't send this token

  • David@QuantumDavid@Quantum Posts: 36Questions: 4Answers: 2

    @SkMicky - perhaps it it's an issue with the Authorisation token?
    If you press F12 to open the inspector, navigate to Application>Storage>Local Storage (with your web-page open) and look for the value associated to the key token, check that.
    I'm not familiar with JWT, where is your authorisation token set in your system?

    If this is not the token error it could be something that's happening over at the API you're retrieving your data from ... If you haven't already go into the inspector (F12) to Network and refresh the page, click on the row where 'Name' corresponds to your Ajax access URL - see if there's any more insightful information in there.

  • SkMickySkMicky Posts: 7Questions: 2Answers: 0

    @David@Quantum it's about "draw" in datatable. Datatable send "draw" to server. This draw sends with numeric value, but that error says that "draw" must be boolean. What's it?

  • David@QuantumDavid@Quantum Posts: 36Questions: 4Answers: 2

    If you check out the documentation for draw() you'll see that the parameter in draw(_params_) is paging.

    To force this to a boolean in your JavaScript try setting paging:

    table = $('#rolesTable').DataTable({
        select: true,
        processing: true,
        serverSide: true,
        ajax:{
            "url": 'http://aaa.bbb.zz:8083/role/data',
            "type": 'POST',
            "dataType":'json',
            "contentType": "application/json;charset=UTF-8",
            "headers": {
                'Authorization': localStorage.getItem('token')
            }
        },
        columns: [
        {
            "ordering": false,
            "data": null,
            "className": "details-control",
            "defaultContent": ''
        },
        {"data": "id", "className": "id"},
        {"data": "name"},
        {"data": "description"}
        ],
        "paging": false
    });
    

    Note the: "paging: false" I've added at the end.

  • SkMickySkMicky Posts: 7Questions: 2Answers: 0

    @David@Quantum No I\m not about draw(), but I'm talking about draw parameter

    draw integer Draw counter. This is used by DataTables to ensure that the Ajax
    returns from server-side processing requests are drawn in
    sequence by DataTables (Ajax requests are asynchronous and
    thus can return out of sequence). This is used as part of the draw
    return parameter (see below).

    This draw parameter is unrecognized with 400 error and message that this must be bool value. I don't configure this draw by myself

  • kthorngrenkthorngren Posts: 20,348Questions: 26Answers: 4,776

    The first place to start is by looking at what the server responds with for the server side ajax request. In the browser's developer tools look at the response. You can post it in the thread so we can see it. This technote will provide steps for this.

    Kevin

  • SkMickySkMicky Posts: 7Questions: 2Answers: 0
    edited October 2019

    {"timestamp":"2019-10-22T11:44:07.475+0000","status":400,"error":"Bad Request","message":"JSON parse error: Unrecognized token 'draw': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'draw': was expecting ('true', 'false' or 'null')\n at [Source: (PushbackInputStream); line: 1, column: 6]","path":"/role/data"} this is response

  • kthorngrenkthorngren Posts: 20,348Questions: 26Answers: 4,776
    Answer ✓

    Sounds like this error is seen in your server logs?

    JSONParseException:Unrecognized token 'draw'

    If so then we need to find out more about your server script. Are you using one of the Datatables provided scripts or your own?

    Probably need to using some debugging in your server script to see what its receiving and why its unable to process it.

    Kevin

  • SkMickySkMicky Posts: 7Questions: 2Answers: 0

    Thanks Kevin. This is not Datatables server script, but I'm frontend developer and cann't see or change server script. This enough for me that problem is on the server side not mine. Thanks

This discussion has been closed.