title: How to cancel an $.ajax request if a previous is running?
body: <p>I have this simple piece of code:</p>
  
  <pre><code>$(document).on("input", "#addFoodSearch", function(event){
     var search = $(this).val();
     $.ajax({ url: "/ajax/search-food.php", type: 'GET', data: { 'search' : search }, dataType: 'json' }).done(
        function(data){
           if (data[0] == 'success'){
              $('#add-food-area').html(data[1]);
              $('#add-food-area').fadeIn();
           }
        }
     );
  });
  </code></pre>
  
  <p>What I want to do is to cancel a previous $.ajax request, if any is running, in case the user types too fast. I need only the latest request to pass, not the whole sequence of them.</p>
  
  <p>How can I do this?</p>