javascript - jqXHR object removes itself and container from an array -
i storing jquery ajax objects inside array can manually cancel call,if has not returned, based on user triggered events. these ajax calls expect run long.
javascript
var ajaxcalls = []; ajaxcalls[0] = $.ajax({...}); $("#cancelbutton").on("click", function() { ajaxcalls[0].abort(); });
the problem exists jqxhr object disappears array after abort() method called.
now looks great when comes managing memory of objects magically removing , cleaning nicely. however, leaves anti-pattern in code looks not cleaning after myself. defeats purpose of me creating remove companion method add method.
is there reason this? if array contains more 1 object re-sizes appropriately.
this array if letters jqxhr objects
['a', 'b', 'c', 'd']
becomes array when jqxhr object 'b' completes
['a', 'c', 'd']
reading code, 1 expect occur
['a', null/undefined, 'c', 'd']
why?
edit:
here fiddle able reproduce doing.
as direct array element:
[ jqxhr, jqxhr, jqxhr ]
http://jsfiddle.net/itanex/uhx8q/
as key value object element in array:
[ { key: "key", value: jqxhr }, { key: "key", value: jqxhr } ]
the complete
callback runs when abort call. happens:
ajaxcalls.pop();
and there goes jqxhr object.
added console.log
show pop
:
Comments
Post a Comment