$('input[name=clientsearch]').on('input',function(e){
var find = $(this).val();
if(find.length == 0){
$('.clientsearch ul').empty();
}
if(find.length >= 2){
$('.clientsearch ul').empty();
$.ajax({
type: "GET",
url: "/panel/search",
data: {"find": find},
cache: false,
success: function(response){
if(response.length == 0){
$('.clientsearch ul').append("<li>"+"По вашему запросу ничего не найдено"+"</li>");
return 0;
}
$.each(response,function (index, value) {
$('.clientsearch ul').append("<a href=''><li>"+value.lastname+" "+value.name+" "+value.middlename+"</li></a>");
});
}
});
}
});
$('#search').on('input', _.throttle(function(e) {
var searchKeyword = $(this).val();
...
}, 1000));
$('input[name=clientsearch]').on('input',function(e){
var query = $(this).val();
var TXhr;
if(query.length >= 2){
$('.clientsearch ul').html("<li>Ищу...</li>");
try{
TXhr.abort();
}
finally{
TXhr = $.ajax({
type: "GET",
url: "/panel/search",
data: {"find": query},
cache: false,
success: function(response){
$('.clientsearch ul').html(response);
}
});
}
}
});