I'm currently using a tool to retrieve addresses in a database on the jQuery event keypress. When the text input loses focus, I cancel every pending requests to avoid the dropdown appears after the user finished to fill in the input. Everything works correctly, but, to finish I Send a final ajax request to go to the next step of my form. This request is really much slower than before I cancelled all these requests. I don't understand why, a cancelled request shouldn't affect the pending one (and I'm sure they are cancelled, looking it in the network tab in chrome tools). I'm using this code :
jQuery.xhrPool = [];
jQuery.xhrPool.abortAll = function() {
jQuery(this).each(function(idx, jqXHR) {
jqXHR.abort();
jQuery('.loader').hide();
});
};
jQuery.ajaxSetup({
beforeSend: function(jqXHR) {
jQuery.xhrPool.push(jqXHR);
},
complete: function(jqXHR) {
var index = jQuery.xhrPool.indexOf(jqXHR);
if (index > -1) {
jQuery.xhrPool.splice(index, 1);
}
}
});
jQuery('#my_input').blur(function(){
jQuery.xhrPool.abortAll();
});
I guess there i an optimization trick I don't get. Thanks for you help.