How to abort running ajax call if new request found
How to abort running ajax call if new request found
tejareddy.423
Posts: 3Questions: 1Answers: 0
Hi I am using Datatables 1.10.13
i have a situation here, how to cancel old request on server side scripting.
while value entered in text field I need to call a function which contains Datatables.
Can any one explain how to achieve it?
This discussion has been closed.
Answers
once the request is made, you can't cancel it but you can ignore it. But do you really need to?
Assuming you mean with serverSide:true, the "draw" value (providing you are setting it in your response from your request on the server side, will keep the transactions in sync to ensure that the second requests does not get written over the first if the come back out of order.
Yes I am using serverSide:true
I have a typical situation here.
onblur of input field I am calling Datatable function (with the value from input field I need to form query)
so on every char entered its calling Datatables and getting the response,
if I entered 10char I don't need 10 success responses, and it is load/time consumption in my case
I saw for ajax abort code
currentRequest = jQuery.ajax({
type: 'POST',
data: 'search_text=' + text,
url: 'AJAX_URL',
beforeSend : function() {
if(currentRequest != null) {
currentRequest.abort();
}
},
success: function(data) {
jQuery('#data').html(data).show();
}
});
But I don't know how to use it in Datatables
I fixed that in my code by removing the handler off the search boxes and replacing it with my own.
It has an added button and watches for the enter key (so two ways to start a search)
Thanks for your help @bindrid
I think I didn't explain it properly
My requirement is not filtering the table
my input field is independent, but depends up on text in the field need to construct query and datatable
my problem is just abort the running once it any new request