function debounce(callback, wait, context = this) { let timeout = null let callbackArgs = null const later = () => callback.apply(context, callbackArgs) return function() { callbackArgs = arguments clearTimeout(timeout) timeout = setTimeout(later, wait) } } $('.who').bind("change keyup input click", function() { const handleScroll = debounce(() => { $.ajax({ type: 'post', url: "search.php", data: {'search':this.value}, response: 'text', success: function(data){ $(".search_result").html(data).fadeIn(); / } }) ; }, 1000) document.querySelector('input').addEventListener('input', handleScroll) }) 
something is not working with a delay. I enter the characters, then a 1 second delay and a bunch of requests are sent. and I need to, in one query, all the entered characters

    1 answer 1

     const handleScroll = debounce(() => { var search=$("#search").val(); $.ajax({ type: 'post', url: "search.php", data: {'search':search}, response: 'text', success: function(data){ $(".search_result").html(data); } }) ; }, 1000); document.querySelector('input').addEventListener('input', handleScroll)