Append form data into a json file
<p>I want to append form data into a json file, here is my code however i'm not sure what I have done wrong. Every time I submit data via post I only get an error response. Where is this code going wrong?</p>

<p><strong>HTML</strong></p>

<pre><code>&lt;form class="ajax form-inline"&gt;
&lt;div class="form-group"&gt;
            &lt;label for="exampleInputAmount"&gt;Yo, whats your first name?&lt;/label&gt;
            &lt;div class="input-group"&gt;
              &lt;input type="text" class="form-control" id="fname" placeholder="First name"&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="exampleInputAmount"&gt;&amp;&amp; Last name?&lt;/label&gt;
            &lt;div class="input-group"&gt;
              &lt;input type="text" class="form-control" id="lname" placeholder="Last name"&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;button type="submit" class="btn btn-primary"&gt;Submit to JSON&lt;/button&gt;
        &lt;/form&gt;
</code></pre>

<p><strong>JS/ Jquery</strong></p>

<pre><code>  $('form.ajax').on('submit', function(){
      var $fname = $("#fname")
            var $lname = $("#lname")
            var object = {
            firstname: $fname.val(),
            lastname: $lname.val(),
            }

            var params = JSON.stringify(object);


            $.ajax({
              type: 'POST',
              data: params,
              dataType: "json",
              url: 'save_to_json.php',

              success: function(data) {
                  console.log('success');
                },
                error: function(data) {
                  console.log('error');
                },
                complete: function() {
                  console.log('complete');
                }
                });
                return false;
e.preventDefault()
            });
</code></pre>

<p><strong>PHP / save_to_json.php</strong></p>

<pre><code>&lt;?php
if (!isset($_POST['params']) &amp;&amp; !empty($_POST['params'])) {
     $params = $_POST['params'];

     $jsonObject = json_encode($params);
     file_put_contents('my_json_data.json', $jsonObject, FILE_APPEND);
 }
 else {
   echo "Noooooooob";
 }

 ?&gt;
</code></pre>