The keyup event is called once for each word entered.

$("-sharpsearch").on("keyup",function (e) {
  e.preventDefault();

  if($(this).val().length > 0){

    $.ajax({
      type: "GET",
      url: "search",
      data: "search="+$("-sharpsearchbar").val(),
      success: function(data){
      
          $("-sharpsearch-result-display").html(data);

      }
    });

  }
});

I now have a problem
but I have joined if ($(this). Val (). Length > 0) {
but if there are five words
he will send out requests five times.
means that I will see search-result-display this event five times.
is there any way to improve this situation?

Jul.29,2021

set a delay. If there is no keyboard event within a certain period of time, the remote call will be triggered, that is, debounce (de-jitter)

  

the author can understand the two concepts of anti-shaking, and throttling!

Menu