title: Jquery Ajax Request Not Sending Post Data
body: <p>I'm successfully making an AJAX call with the Jquery <code>$.ajax</code> method, in that the file it's POSTing to is getting called and executing. However, no POST data is being sent. All I want to do is send the data and have it received by the file; I don't care about returning data.</p>
  
  <p>I've tried changing it to GET, which didn't yield results. I passed GET data in the URL which was received (obviously, I guess). I've also tried changing the data type that I'm sending...none of this has given me any ideas as to what I'm doing wrong. I've also browsed the numerous questions here with similar titles, but nothing seemed to fix this issue. Though I'm sure it's something simple.</p>
  
  <p>Other variables that may be relevant: I'm using Knockout JS. I'm using .htaccess redirects to create a single point of entry in a /public folder.</p>
  
  <p>And without further ado, here's the code:</p>
  
  <h2>page.html</h2>
  
  <pre><code>&lt;button data-bind="click: save"&gt;Save&lt;/button&gt;
  </code></pre>
  
  <p>If you're unfamiliar with KOJS, it basically just calls the function save when you click it. I'm pretty sure this is working properly.</p>
  
  <h2>models.js</h2>
  
  <pre><code>self.save = function() {
      var jsonData = ko.toJSON(self.tasks);
      $.ajax("http://test.local.com/js/post.php", {
          data: jsonData,
          type: "post", contentType: "application/json",
          success: function(result) { alert(jsonData) }
      });
  };
  </code></pre>
  
  <p>That alert is giving me a nicely formatted JSON object, like</p>
  
  <pre><code>[{"title": "Clean up the dog"},{"title": "Warm up the old pasta"}]
  </code></pre>
  
  <p>It's the post file, I think, where my error is? The $_POST array is empty. And if I change it to send as GET, that's also empty. I put comments in the code explaining things.</p>
  
  <h2>post.php</h2>
  
  <p>
  
  <pre><code>if (isset($_POST)) {
    //It does get inside this if. That's good at least, right?
  
    $my_file = 'file.txt';
    $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
    //It will make this file.
  
    fwrite($handle, print_r($_POST));
    //Prints "1" without the quotes
  
  
    foreach ($_POST as $key =&gt; $value) {
      fwrite($handle, 'your data: '.$value.'; ');
    }
    //Prints nothing
  }
  </code></pre>
  
  <p>Any thoughts as to why this won't send any POST data? I'm sure it's something silly. Thanks!</p>