title: Ajax post value and store in php variable
body: <p>I have here a ajax. What I need to know if it possible to send back the post value and store it in php variable in the mainpage depending in onchange event? $_POST["mainlist_id"] store in php var?</p>
  
  <p>getajax.php</p>
  
  <pre><code>&lt;?php
  if (isset($_POST["mainlist_id"])) {
      $mysqli = new mysqli("localhost", "root", "", "2015");
      $main = $mysqli-&gt;real_escape_string($_POST["mainlist_id"]);
  
  
  $result1 = $mysqli-&gt;query("SELECT * FROM code WHERE cat_code='$main' GROUP BY item_code ORDER BY item");
  
      $option1 = '';
       while($row = $result1-&gt;fetch_assoc())
          {
          $option1 .= '&lt;option value = "'.$row['item'].'"&gt;'.$row['item'].'&lt;/option&gt;';
          }
          echo $option1;
      }
  ?&gt;
  </code></pre>
  
  <p>Mainpage</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $('#main').change(function () {
          $.ajax({
              url: 'getajax.php',
              data: {
                  mainlist_id: $(this).val()
              },
              dataType: 'html',
              type: 'POST',
              success: function (data) {
                  $('#languages').html(data);
              }
          });
      });
  &lt;/script&gt;
  </code></pre>