I have the following in DataTables 1.10.15
var myTable = $('#myTable').DataTable( {
"serverSide": true,
"ajax": {
"url" : "/getData.php",
"data" : function ( d ) {
// Search input data
d.ecNumber = $('#ecNumber').val(),
d.casNumber = $('#casNumber').val(),
d.substanceName = $('#substanceName').val()
},
"method" : "POST",
"dataSrc": function ( json ) {
if (json.form_errors) {
// ...
}
return json.data;
}
},
});
My application works with some other JavaScript such that a user has to enter 3 or more characters before the ajax request happens (I use myTable.draw();
to trigger it).
I asked about how to abort ajax requests that may still be running and a reply I got was to set a flag to say whether or not the ajax request was running.
So in normal jquery I could do something like this:
var processing = null;
if (processing !== null) {
processing.abort();
}
processing = $.ajax({
// ...
success: function(result){
processing = null;
}
});
I've had a look over the documentation about using ajax as a function. But I can't understand how to add the code - plus the flag - in to something like the example below. I understand that the callback
has to be the data to go in the table (presumably json.data
in my original code?). But how does the other code fit in to this?
$('#myTable').dataTable( {
"ajax": function (data, callback, settings) {
}
});