You can save the "global" currentAjaxRequest , which contains the structure of the last XHR request. Then you can abort to execute the current request when creating a new one.
For instance:
var currentAjaxRequest = null; function autoCompleteStuff() { if(currentAjaxRequest !== null) { currentAjaxRequest.abort(); } currentAjaxRequest = $.get(..., function(...) { currentAjaxRequest = null; ... }); }
To avoid name conflicts, wrap this in an anonymous, instantly executed function, if necessary.
source share