In a search input, an ajax request is made to each letter pressed through a KeyPress in the field, however with each key pressed a new request is made, that is, if the user types fast, and he type a value of 10 letters, 10 different requests will be made, and the same 10 will be processed and sent back through my PHP, and this may cause me some confusion in the return of this data to the user if a previous request is processed late, so I want it with each key pressed, previous requests are aborted and then sends the new request.
$(document).on("keypress", ".meuInput", function(){
var val = $(this).val();
if(val != ''){
jQuery.ajax({
type: "POST",
url: "meuarquivo.php",
datatype: "json",
data: {src: val},
success: function(data)
{
//processa retorno
}
});
});