Jquery ajax search debounce

后端 未结 1 812
南笙
南笙 2020-12-11 10:31

I am building a live search for a website that will return results based on what the user types. I only want the request to be sent when the user has finished typing.

相关标签:
1条回答
  • 2020-12-11 11:04

    Maybe your users cannot type fast enough. Set the wait parameter of the _.debounce function to be longer than the 100ms in your example: (see specs: _.debounce(function, wait, [immediate]).

    $('#search_term').on('keyup', _.debounce(function (e) {
       $.ajax({
            type: "GET",
            url: "quicksearch.php",
            data: { search_term:$('#search_term').val()},
            success: function(msg){$('#quick_search_results').html(msg).slideDown();}
       });
    }, 300)); // < try 300 rather than 100
    
    0 讨论(0)
提交回复
热议问题