'JS Datatable not displaying AJAX response

Datatable is not displaying the response of an AJAX call to flask backend.

The data is retrieved as I can see it in the console.log of the success field of the AJAX call, however its not populating in the table.

Here is the JSON:

{'events': 
 [
  {
   'TIME': 'Evening', 
   'DESCRIPTION': 'test1'
  }, 
{
   'TIME': 'Morning', 
   'DESCRIPTION': 'test2'
  }
 ]
}

This is the JS part:

function load_table() {
    var payload = {'from_date': $('#from_date').val(), 'to_date': $('#to_date').val()}

    $('#table').DataTable({
        pageLength: 50,
        paging: true,
        ajax: {
            url: "data/get-events/" + JSON.stringify(payload),
            dataType: "json",
            type: 'GET',
            error: function(e){
                alert(e);
            },
            success: function(e){
                console.log(e);
            },
            dataSrc: 'events'
        },
        columns: [
        { title: 'Time', data: 'TIME'},
        { title: 'Event', data: 'DESCRIPTION'}
    ],
        bDestroy: true,
    });


}

I tried the tens of answers to my similar question but none of them worked.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source