0

ajax request in jquery datatable makes multiple requests in server side processing rather than one at a time. The table is initialized on document.ready().

I want to abort the ajax call inside jquery datatable once the response is received.

Is there any way to stop second requests on response success?

document.ready(function() {

        $("#myTable").DataTable({
        "processing": true, // for show progress bar
        "serverSide": true, // for process server side
        "orderMulti": false, // for disable multiple column at once
        "ajax": {
            "url": "/home/LoadData",
            "type": "Get",
            "datatype": "json"
            "data":{ date:'date'},// parameter on controller to filter records 
        },
        "columns": [
                { "data": "ContactName", "name": "ContactName", "autoWidth": true },
                { "data": "CompanyName", "name": "CompanyName", "autoWidth": true },
                { "data": "Phone", "name": "Phone", "autoWidth": true },
                { "data": "Country", "name": "Country", "autoWidth": true },
                { "data": "City", "name": "City", "autoWidth": true },
                { "data": "PostalCode", "name": "PostalCode", "autoWidth": true }
        ]
    });
rashidali
  • 330
  • 1
  • 5
  • 16

2 Answers2

0

It's hard to say without seeing the code, but if you have a handle on the event object you can do something like evt.preventDefault() to prevent the default form submission from sending.

BuffChuck
  • 1
  • 2
0

https://datatables.net/manual/ajax

https://m.datatables.net/forums/discussion/32107/how-to-load-an-array-of-json-objects-to-datatables

you can feed it manually by setting the column property

$('#myTable').DataTable( {
    ajax: ...
} );

// or!

$('#myTable').DataTable( {
    ajax: ...,
    columns: [
        { data: 0 },
        { data: 1 },
        { data: 2 },
        { data: 3 },
        { data: 4 },
        { data: 5 }
    ]
} );
nullqube
  • 2,959
  • 19
  • 18
  • https://stackoverflow.com/questions/27778389/how-to-manually-update-datatables-table-with-new-json-data – nullqube Nov 15 '18 at 07:08
  • This solution worked for this one as well https://stackoverflow.com/questions/53284402/prevent-multiple-ajax-calls-from-jquery-datatable-on-server-side-pagination – rashidali Nov 17 '18 at 16:19