Advertisement
rujing

Untitled

Jan 13th, 2021
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. $(document).ready(function(){
  3.   var timerID;
  4.     $('.search__form input[name="s"]').keyup(function(){
  5.     var $thisVal = $(this).val();
  6.  
  7.       if($thisVal.length == 0)
  8.       {
  9.         $('.search__result-all').hide();
  10.         $('.search__result').hide();
  11.         $('.search__loader').hide();
  12.         $('.search__not-result').show();
  13.       } else {
  14.  
  15.       if(typeof timerID != 'undefined')
  16.       {
  17.           clearTimeout(timerID);
  18.       }
  19.  
  20.       $('.search__result-all').hide();
  21.       $('.search__result').hide();
  22.       $('.search__not-result').hide();
  23.       $('.search__loader').show();
  24.  
  25.       timerID = setTimeout(function () {
  26.         $.get( '/search/?&s=' + $thisVal + '&ajax-search=true', function( data ) {
  27.           //data = JSON.parse(data);
  28.           if(data.length > 0)
  29.           {
  30.             $('.search__result').html(data);
  31.             $('.search__not-result').hide();
  32.  
  33.             $('.search__result-all > a').attr('href', '/search/?s=' + $thisVal);
  34.             $('.search__result-all').show();
  35.             $('.search__result').show();
  36.             $('.search__loader').hide();
  37.           }
  38.           else {
  39.             $('.search__result-all').hide();
  40.             $('.search__result').hide();
  41.             $('.search__loader').hide();
  42.             $('.search__not-result').show();
  43.           }
  44.  
  45.         });
  46.       }, 2000);
  47.     }
  48.  
  49.     });
  50.  
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement