Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill previous AJAX calls in DataTables

Ok i have a function like

So when this function is called the AJAX request is made but if I again call the same function. The current request is made but the previous call is not killed. I want the datatable to kill any previous calls and run only the latest one.

I'm not sure how to do this.

like image 548
Anonymous Avatar asked Dec 18 '22 17:12

Anonymous


1 Answers

This is how I do it with DataTables 1.10.16

var table = $('#table').DataTable({
    ajax: {
        url: '/datatable',
        type: 'POST',
        beforeSend: function() {
            if (table.hasOwnProperty('settings')) {
                table.settings()[0].jqXHR.abort();
            }
        }
    }
});
like image 155
Abdul Manaf Saparuddin Avatar answered Dec 26 '22 17:12

Abdul Manaf Saparuddin