title: Live Search With jquery AJAX?
body: <p>How can I create a live search with Jquery AJAX, I used keypress or keyup event to loop query, but if I type 3 characters or more the AJAX will do 3 times or more.</p>
  
  <p><strong>My form:</strong></p>
  
  <pre><code>&lt;input class="keyword-search" type="text" name="s" autocomplete="off" placeholder="Where do you want to go?"&gt;
  </code></pre>
  
  <p><strong>Here my AJAX:</strong> </p>
  
  <pre><code>&lt;script&gt;
    jQuery(document).ready(function(){
              (function($){
                  $(".keyword-search").keypress(function(){
                      var keyword = $(this).val(); 
                       $(".search-appear").empty();
                      $.ajax({
                          type: "post",
                          url: "&lt;?php echo admin_url( 'admin-ajax.php' ); ?&gt;",
                          data: { action: 'get_tour', keyword: keyword },
                          beforeSend: function() {$("#loading").fadeIn('slow');},
                          success: function(data) {
                              $("#loading").fadeOut('slow');
                              $(".search-appear").append(data);
                               }
                      });
                  });
              })(jQuery);
          });
  &lt;/script&gt;   
  </code></pre>
  
  <p><strong>And Here is my demo function:</strong></p>
  
  <pre><code>function get_tour()
              echo 'Do something!';
         ?&gt;
        &lt;?php  die(); }
  </code></pre>
  
  <p>And this is result when I type 3 characters:
  <a href="https://i.stack.imgur.com/WgfDo.jpg" rel="nofollow noreferrer">type 3 characters</a>
  I type 2 chars:
  <a href="https://i.stack.imgur.com/WgfDo.jpg" rel="nofollow noreferrer">type 2 characters</a>
  Who can help me it work 1 time no matter how many key press. Or it work fine anyway ! Thanks a lot !!</p>