title: How to POST with AJAX using just an a tag
body: <p>I have an <code>a</code> tag that is dynamically generated with database content, it includes a data-target that I capture in javascript when it is clicked on, this is an example of one of the generated buttons:</p>
  
  <p><code>&lt;a href="#" data-target="edit/?id=1"&gt;Edit&lt;/a&gt;</code></p>
  
  <p>Simple, right?</p>
  
  <p>Now, what I do in the JS when it is clicked, is as so:</p>
  
  <pre><code>var $this = $(this),
      $target = $this.data("target"),
      $endpointURL = "";
  
  $endpointURL = $target.split("?id=")[0];
  
  $id = $target.split("?id=")[1];
  </code></pre>
  
  <p>This allows me to set the endpoint I want, in out example above, it would be "edit" and also set the id which is just a number at this point.</p>
  
  <p>Now, I have to POST this ID to the edit endpoint to return the right info, correct?</p>
  
  <p>So, here is my AJAX for that:</p>
  
  <pre><code>$.ajax({
          type: "POST",
          data: '{"id": ' + $id + ' }',
          url: "../assets/scripts/php/" + $endpointURL,
          success: function (data) {
              $("#content-lockup").html(data);
          },
          error: function (jqXHR, textStatus, errorThrown) {
              console.log("error: " + textStatus + ", error thrown: " + errorThrown);
          }
      });
  </code></pre>
  
  <p>This does not throw an error and does indeed output a var dump of the $_POST array as I have set it to, however it doesnt contain my ID that I passed over, here is the code on the endpoint and a screenshot of the output:</p>
  
  <pre><code>&lt;?php
  
  var_dump($_POST);
  
  ?&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/A6Y0G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A6Y0G.png" alt="enter image description here"></a></p>
  
  <p>Why would the vardump on $_POST not contain the id that I passed over in the apparently successful AJAX request?</p>
  
  <p>What I expect is that I can say on the endpoint, something like:</p>
  
  <pre><code>$id = $_POST['id'];
  </code></pre>
  
  <p>Maybe its something obvious that i'm doing wrong but yeah, any ideas?</p>