How to use JSON.stringify in datatable?

How to use JSON.stringify in datatable?

mastersusemastersuse Posts: 61Questions: 28Answers: 0

I have read many solutions but not solve my problem.
I want to send some parameter prior to Ajax.
How to put JSON.stringify in datatable?

I got this ajax error

1st try

$('#userTable').DataTable({
    processing: true,
    ajax: { 
        url: api_url,
        crossDomain : true,
        type : "POST",
        cache : false,
        dataType : "json",
        contentType: "application/json",
        dataSrc : "",
        data: {
            "uid": $("#session_userid").text(),  // this is read user session
            "tokenid": $("#session_tokenid").text(),   // this is read user token session
            "item": "user",
            "action": "read",
            "type": "1",
            "keyword": ""
        }
    },
    columns: [
        { data : "full_name" },
        { data : "userid" },
        { data : "level" },
    ],
});

2nd try

$('#userTable').DataTable({
    processing: true,
    ajax: { 
        url: api_url,
        crossDomain : true,
        type : "POST",
        cache : false,
        dataType : "json",
        contentType: "application/json",
        dataSrc : "",
        data: {
            return JSON.stringify({"uid": $("#session_userid").text(), "tokenid": $("#session_tokenid").text(), "item": "user", "action": "read", "type": "1", "keyword": "" });
        }
    },
    columns: [
        { data : "full_name" },
        { data : "userid" },
        { data : "level" },
    ],
});

Answers

This discussion has been closed.