title: jQuery $.ajax post to PHP in the same file not working
body: <p>This the code:</p>
  
  <pre><code>&lt;script&gt;
  $( document ).ready(function() {
  
      $( ".button" ).click(function() {
  
          var clickBtnValue = $(this).val();
          $.ajax({
              //url: '', // url is empty because I'm working in the same file
              data: {'action': clickBtnValue},
              type: 'post',
              success: function(result) {
              alert("action performed successfully"); //this alert is fired
              }
  
      });
  
  });
  });
  &lt;/script&gt;
  
  &lt;div&gt;Button clicked:
  &lt;?php 
  if (isset($_POST['action'])) {
      switch ($_POST['action']) {
          case 'insert':
              echo "select button!";
              break;
          case 'select':
              echo "insert button!";
              break;
      }
  }
  ?&gt;
  &lt;/div&gt;
  
  &lt;input type="submit" class="button" name="insert" value="insert" /&gt;
  &lt;input type="submit" class="button" name="select" value="select" /&gt;
  </code></pre>
  
  <p>In the inspector I can see a posted value, so why  <code>echo "insert button!";</code> or <code>echo "select button!";</code> are not working?</p>