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!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36cb3-2c036.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36cb3-2c036.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?