abort previous ajax request
abort previous ajax request
JonnyEggins
Posts: 4Questions: 1Answers: 0
Hi there,
I used this code for datatable...
$('#table').DataTable({
"destroy": true,
"processing": true,
"serverSide": true,
"columnDefs": [{
"targets": 0,
"orderable": false
}],
"ajax": {
url: baseURL + checkVal,
type: "post",
xhr: function() {
var xhr = $.ajaxSettings.xhr();
xhr.upload.onprogress = function(e) {
xhr.abort(); //abort all current request here
};
return xhr;
},
error: function() {
$(".employee-grid-error").html("");
$("#table").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
}
},
'initComplete': function(settings, json) {
//code here
}
});
when I abort it will abort all current request... I want to stop all previous request when current request start running ... How to do that...
I used your all code which is posted in answer. But i can't get any value of settings.jqXHR or settings.jqXHR.abort() anywhere...
please help me how to abort all previous request..
Thanks in advance
This discussion has been closed.
Answers
is where you will find that property.
But I urge cation with the
settings()
method - it provides access to internal properties. Changing them can have undefined effects!Allan
can you please tell me that where i put this code ?
Wherever it is that you are trying to cancel the Ajax request.
Allan
I want to stop previous ajax request......when new request running then all previous request must be abort. But new request must be running
table.settings()[0].jqXHR.abort()
before you trigger the next Ajax request.Allan
Thanks allan ......It's working
Hi. I put it in drawCallback and preDrawCallback and it doesn't work. Could you please help me?
settings.jqXHR.abort() doesn't do anything
Happy to help - please link to a test case showing the issue.
Allan
Thanks. The result has more than 2 millions of records. When you search a name in the list, it will force to get 2 million for every letter. It is too much for this database
https://jsfiddle.net/akarina/3y1fx07k/5/
I'm not entirely clear how the 2 million records relates to
preDrawcallback
? The code you linked to shows you are using server-side processing - does your/api/result
end point support server-side processing? It should only be getting 100, 250 or 500 records at a time if so.Allan
Sorry for the delay in replying. When you search "a" in the search-box, it can retrieve 2 millions of records. If many people are using the application, it will be worst.
I have to search all records
Not sure what DB you are using but your server side search should support a limit (page length) and offset (page number) options to return the specific subset of dat based on the page being viewed.
Kevin
the search has to be on the 2 millions of records, all of them
Again, I'm not sure which DB you are using but the limit and offset (might be different for your DB) are placed in the query to limit the records returned to the 2 million records that fall within those parameters.
However it sounds like your concern is having multiple users searching at the same time. You might be interested in the
searchDelay
to help throttle the searches. This thread may be of interest too:https://datatables.net/forums/discussion/comment/116229/#Comment_116229
If you want to get
settings.jqXHR.abort()
working then please post a link to your page or a test case for debugging why its not working.Kevin
We'd need to know if you are actually using server-side processing. As I asked above:
Allan
p.s. Yes - as Kevin says, we'd need a link to a test case showing the issue to be able to offer any help. Currently we are just guessing at the issue.