title: How to get data sent from AJAX POST in PHP?
body: <p>I am trying to get POST data using <code>AJAX &amp; JQUERY</code></p>
  
  <p>I have a bootstrap dropdown in which i show some values from database.
  I want to pass the item i selected as POST to my PHP.</p>
  
  <p>My dropdown is like this:</p>
  
  <pre><code>&lt;li class="dropdown"&gt;
    &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"&gt;Your Sites &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
    &lt;ul class="dropdown-menu"&gt;
      &lt;?php
        foreach($sites as $site)
        {
          echo "&lt;li class='specialLink' id='".$site-&gt;site_key."'&gt;&lt;a href='#'&gt;".$site-&gt;site_key."&lt;/a&gt;&lt;/li&gt;";
        }
      ?&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>Now the my problem is when i echo the POST Values in PHP i get nothing, while if i alert the data from ajax then it shows me the correct value.</p>
  
  <p>Also if i open my browser console in can see the values i select in <strong>Network->XHR</strong> tab.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $( ".specialLink" ).click(function() {
      var site = this.id;
      console.log(site);
      var url= "&lt;?php echo base_url('customer/dashboard/index') ?&gt;"; 
  
       //get value for throw to controller
  
      $.ajax({ 
          type: "POST", //send with post 
          url: "&lt;?php echo base_url('customer/dashboard/index') ?&gt;", 
          data: {site:site}, 
          success:function(data){ 
  
          },
  
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>Trying to get Values like this in PHP:</p>
  
  <pre><code> if(!empty($_POST))
      {
         //$site = $_POST['site'];
  
          echo $this-&gt;input-&gt;post('site');
         //$this-&gt;session-&gt;set_userdata('site', $site);
      }
  </code></pre>
  
  <p>In Console i can see the item selected like this:
  <a href="https://i.stack.imgur.com/X7wts.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X7wts.png" alt="image"></a></p>
  
  <pre><code>Request URL:http://127.0.0.1/bizrtc/customer/dashboard/index
  Request Method:POST
  Status Code:200 OK
  Form Data
  view source
  view URL encoded
  site:HT45-YT6T
  </code></pre>