title: Passing variable with Ajax in WordPress
body: <p>I am trying to pass variable when user click on link to page <code>single.php</code></p>
  
  <p>Here is my code</p>
  
  <pre><code>&lt;a href='#' id='8' class='clickme' style='font-weight:bold;color:white;font-size:16px;'&gt;";
  </code></pre>
  
  <p>In <code>function.php</code>, I put this code:</p>
  
  <pre><code>/////////////////////////////////////////////////////////
  add_action( 'wp_head', 'myajaxcall' );
  
  function myajaxcall(){ ?&gt;
  &lt;script type="text/javascript"&gt;
  
  jQuery(document).ready(function($) {
          jQuery(".clickme").click( function() {
  
      // We'll pass this variable to the PHP function example_ajax_request
     var id = $('.clickme').attr('id');
  
      // This does the ajax request
      $.ajax({
          url: &lt;?php echo admin_url( 'admin-ajax.php'); ?&gt;,
          data: {
              'action':'get_sidebar_request',
              'page_id' : id
          },
  
        //  beforeSend: function (jqXHR, settings)
        //  {
          //   alert( url = settings.url);
            //},
  
          success:function(data){
              alert(data);
          },
  
          error: function(errorThrown){
              //alert(errorThrown);
  
          }
      });
  });
  });
  &lt;/script&gt;
  &lt;?php }
  
  add_action( 'wp_ajax_get_sidebar_request', 'idAjax' );
  add_action( 'wp_ajax_nopriv_get_sidebar_request', 'idAjax' );
  
  function idAjax()
      {
       require( get_template_directory() . '/single.php' );  
      } 
  
  /////////////////////////////////////////////////////////////////////
  </code></pre>
  
  <p>And in file <code>`single.php</code>, when I want to get the passed variable, I put this code:</p>
  
  <pre><code>$page_id=0;
  $page_id =  $_REQUEST['page_id'];
  echo "page_id=".$page_id;
  </code></pre>
  
  <p>But the variable isn't passing to <code>single.php</code>. I try to echo it, and nothing happens.</p>
  
  <p>Can you help me?</p>