No valid JSON

No valid JSON

davidhernandezdavidhernandez Posts: 4Questions: 1Answers: 0

I have a datatable declaration:

 var table = $('#dtAssistance').DataTable({

            "processing": true,
            "serverSide": true,

            "ajax": $.ajax({
                dataSrc: "",
                method: "POST",
                url: "../testing/LogGetter.php",
                dataType: "json",
                data: {
                    target: "SuscriptionAdministrator",
                    type: "getAssistanceLog"
                }
            }),

            "columns": [
                {data: "DateTime"},
                {data: "Name"},
            ],
            "order": [0,"des"]

        });

And i get an invalid json response message.
When i follow the steps to verify jason response it seems to be a valid response.
Any ideas that whats happend?

Answers

  • davidhernandezdavidhernandez Posts: 4Questions: 1Answers: 0

    the picture is the response that i recieve to the request

  • davidhernandezdavidhernandez Posts: 4Questions: 1Answers: 0

    jquery ajax dont support dataSrc attribute. I resolved the problem like this:

    var table = $('#dtAssistance').DataTable({
               "processing": true,
               "serverSide": true,
     
               "ajax": {
                   "dataSrc": "",
                   "method": "POST",
                   "url": "../testing/LogGetter.php",
                   "dataType": "json",
                   "data": {
                       target: "SuscriptionAdministrator",
                       type: "getAssistanceLog"
                   }
               },
     
               "columns": [
                   {data: "DateTime"},
                   {data: "Name"},
               ],
               "order": [0,"des"]
     
           });
    

    `

  • allanallan Posts: 61,657Questions: 1Answers: 10,094 Site admin

    I resolved the problem like this

    Yes. That is the correct way to do it.

    The code in your first post was assigning the result of $.ajax() to the ajax option in DataTables which won't work.

    Allan

This discussion has been closed.