I have a function that runs an ajax call on the change of an input.

But, there is a chance that the function will be fired again before the previous ajax call has completed.

My question is, how would I abort the previous ajax call before starting a new one?
Without using a global variable. (See answer to a similar question here)

jsfiddle of my current code: 

Javascript:

var filterCandidates = function(form){
    //Previous request needs to be aborted.
    var request = $.ajax({
        type: 'POST',
        url: '/echo/json/',
        data: {
            json: JSON.stringify({
                count: 1
            })
        },
        success: function(data){
            if(typeof data !== 'undefined'){
                jQuery('.count').text(data.count)
                console.log(data.count);
            }
        }
    });
};

if(jQuery('#search').length &gt; 0){
    var form = jQuery('#search');
    jQuery(form).find(':input').change(function() {
        filterCandidates(form);
    });
    filterCandidates(form);
}


HTML:

&lt;form id="search" name="search"&gt;
    &lt;input name="test" type="text" /&gt;
    &lt;input name="testtwo" type="text" /&gt;
&lt;/form&gt;
&lt;span class="count"&gt;&lt;/span&gt;



Question: How can I resend an application on Careers?
Answer: Right now there's no way to resubmit an application. This is probably an oversight on our part considering a job listing can be re-posted years later. I'll add this our ever growing feature request Trello board.

Nevermind, the devs are already looking into how to fix it as we speak.