Killing a request
Killing a request
GregP
Posts: 500Questions: 10Answers: 0
I have a "details view" combined with a polling application. The code is already in place to stop polling when someone opens a details row.
However...
A race condition can be created whereby the request is sent out, the user clicks an "open details" icon, and then the request returns. When the request returns, the table is re-rendered and therefore the details view is re-closed.
I did a bit of poking around and discovered that if I call .abort() on the XHR object, it will cancel normal (plain ol' $.ajax()) requests, but I"m not sure where the DT API hooks into the returned data or if that will ruin things. Also, I'm not sure how to access the XHR object, because my "oTable" variable (I name it differently, but in the convention of the example code here) is a DT object, not an XHR object.
What I would like to do is this:
[code]
$('#wrapper').on('click', '.details_button', function(e) {
e.preventDefault();
xhr.abort(); // I do not actually know how to grab the xhr object, though
do_the_rest_of_my_stuff();
});
[/code]
If I can dynamically get the DT object and then get the XHR object from within, that would be the best route (ie. using 'this' to navigate to the DT object). But I don't mind doing it with my oTable variable, either.
Thanks!
However...
A race condition can be created whereby the request is sent out, the user clicks an "open details" icon, and then the request returns. When the request returns, the table is re-rendered and therefore the details view is re-closed.
I did a bit of poking around and discovered that if I call .abort() on the XHR object, it will cancel normal (plain ol' $.ajax()) requests, but I"m not sure where the DT API hooks into the returned data or if that will ruin things. Also, I'm not sure how to access the XHR object, because my "oTable" variable (I name it differently, but in the convention of the example code here) is a DT object, not an XHR object.
What I would like to do is this:
[code]
$('#wrapper').on('click', '.details_button', function(e) {
e.preventDefault();
xhr.abort(); // I do not actually know how to grab the xhr object, though
do_the_rest_of_my_stuff();
});
[/code]
If I can dynamically get the DT object and then get the XHR object from within, that would be the best route (ie. using 'this' to navigate to the DT object). But I don't mind doing it with my oTable variable, either.
Thanks!
This discussion has been closed.
Replies
Allan
Before:
[code]
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
$.ajax( {
//etc
})
[/code]
After:
[code]
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
// etc
})
[/code]