title: No success with retrieving POST Data from AJAX Call to PHP
body: <p>I want to retrieve data from ajax call. I get data from a html select tag without any submit button that created by php code and then i want to pass them to an ajax call and use them in a php code at the same file.</p>
  <p>I tried this code but no success:</p>
  <pre><code>&lt;?php
      if (isset($_POST['value'])) {
          $selected_option = $_POST['value'];
          echo $selected_option;
          exit;
      }
      ?&gt;
  
  &lt;script&gt;
      $(document).ready(function() {
          $('#percents').change(pass_the_value());
      });
  
      function pass_the_value() {
          var selected = $('#percents').val();
          $.ajax({
              type: 'POST',
              data: {
                  value: selected
              },
              success: function() {
                  alert(data);
              },
              error: function() {
                  alert('failure');
              }
          });
      }
  &lt;/script&gt;
  
  &lt;div&gt;
          &lt;select name='percents' id='percents' onchange='pass_the_value()'&gt;
              &lt;option value=&quot;0.1&quot; selected=&quot;selected&quot;&gt;10%&lt;/option&gt;
              &lt;?php
  
              // A sample array
              $products = array(
                  &quot;0.2&quot; =&gt; &quot;20%&quot;,
                  &quot;0.3&quot; =&gt; &quot;30%&quot;,
                  &quot;0.4&quot; =&gt; &quot;40%&quot;,
                  &quot;0.5&quot; =&gt; &quot;50%&quot;,
                  &quot;0.6&quot; =&gt; &quot;60%&quot;,
                  &quot;0.7&quot; =&gt; &quot;70%&quot;
              );
  
              foreach ($products as $key =&gt; $item) {
  
                  echo &quot;&lt;option value='{$key}'&gt;$item&lt;/option&gt;&quot;;
              }
              ?&gt;
          &lt;/select&gt;
      &lt;/div&gt;
  </code></pre>
  <p>This is what i get in console log</p>
  <pre><code>(index):20 Uncaught ReferenceError: data is not defined
      at Object.success
  </code></pre>
  <p>and this as php error:</p>
  <pre><code>Undefined index: value in C:\xampp7\htdocs\test\index.php on line 3
  </code></pre>