DataTable server call not working

DataTable server call not working

rajkumarpbrajkumarpb Posts: 1Questions: 1Answers: 0

So I'm facing this weird issue.

The below is how I initialise data table and its working fine.

$(document).ready(function() {
    mytable = $('#table')

    //datatables
    table = $('#table').DataTable({

        "processing": true, //Feature control the processing indicator.
        "serverSide": true, //Feature control DataTables' server-side processing mode.
        "order": [], //Initial no order

        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "ajax_list/"+$("#report_id").val(),
            "type": "POST",            
        },

        //Set column definition initialisation properties.
        "columnDefs": [
            {
                "targets": [ 0 ], //first column
                "orderable": false, //set not orderable
            },
            {
                "targets": [ -1 ], //last column
                "orderable": false, //set not orderable
            },
        ],
    });   
});

But the moment I add any new JS functions in the same JS file, the data table ajax call to server is not happening. I can't see any network call registered in chrome dev tools. This is how it looks after I add few lines of code.

$(document).ready(function() {

    mytable = $('#table')

    //datatables
    table = $('#table').DataTable({

        "processing": true, //Feature control the processing indicator.
        "serverSide": true, //Feature control DataTables' server-side processing mode.
        "order": [], //Initial no order.

        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "ajax_list/"+$("#report_id").val(),
            "type": "POST",            
        },

        //Set column definition initialisation properties.
        "columnDefs": [
            {
                "targets": [ 0 ], //first column
                "orderable": false, //set not orderable
            },
            {
                "targets": [ -1 ], //last column
                "orderable": false, //set not orderable
            },
        ],
    });  


function runSearch() {
    var reportId = $("#report_id").val(),
    var fromDate = $('#from_date').val();
    var toDate = $('#to_date');    
    $.post('ajax_list/'+reportId, { 'fromDate': fromDate, 'toDate' : toDate }, function (data) {            
        table.clear();
        table.rows.add(data).draw();
        mytable.show();            
        $(window).scrollTop('0');
    }).error(function () {
        alert('Error');        
    });     
}
});

Please help me what's wrong with this code? Thanks in advance!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    Answer ✓

    You have a syntax error in line 33. There is a comma instead of semi colon at the end of the line. When Javascript doesn't work you should take a look at the browser's console for errors.

    Kevin

This discussion has been closed.