title: How to use Jquery to retrieve ajax search results for wordpress
body: <p>I need to set up wordpress ajax search results but my method isn't retrieving the results when the button is clicked and is instead redirecting me to another site ( myurl.com?s=term ). I called admin-ajax.php correctly but set this up incorrectly. Any ideas what's causing the problem?</p>
  
  <pre><code>//Script to activate ajax
   jQuery(document).ready(function($){
    var search_val=$("#s").val();
    $('#searchsubmit').click(function(){
      $.post(
          WPaAjax.ajaxurl,
          {
              action : 'wpa56343_search',
              search_val : search_val
          },
          function( response ) {
              $('#results').append( response );
          }
      );
     });
  
   });
  
  //function to setup wp_query
  add_action('wp_ajax_wpa56343_search', 'wpa56343_search');
  function wpa56343_search(){
    global $wp_query;
    $search = $_POST['search_val'];
    $args = array(
      's' =&gt; $search,
      'posts_per_page' =&gt; 5
    );
    $wp_query = new WP_Query( $args );
  
    get_template_part( 'search-results' );
  
    exit;
  }
  
  //html
  
    &lt;div id="my_search"&gt;
     &lt;form role="search" method="get" id="searchform" action="http://myurl.com/" &gt;
      &lt;input type="text" value="" name="s" id="s" /&gt;
      &lt;input type="submit" id="searchsubmit" value="Search" /&gt;
     &lt;/form&gt;
    &lt;/div&gt;
    &lt;div id="results"&gt;&lt;/div&gt;  
  </code></pre>