title: Ajax Sending data (JSON) throught POST
body: <p>Someone can see why it shows the error Maximum call stack size exceeded? And why is not working the script? UPDATE: I added the php code that don't put the value "domain" and I updated the JS code.</p>
  
  <pre><code>    function addentrys() {
      var nwentry =  {};
      el = document.getElementById('addname').value;
      eldmn = document.getElementById('adddomain').value;
      nwentry.name = el;
      nwentry.domain = eldmn;
      $.ajax({
          type: 'POST',
          url: 'api/domain',
          dataType: 'json',
          data: nwentry,
          succes: function(data) {
              alert('Ok')
          }
      })
  }
  </code></pre>
  
  <p>php:</p>
  
  <pre><code>//ADD
  $app-&gt;post('/domain', function () {
      $jsonContents = file_get_contents('data/data.json');
      $name = $_POST['name'];
      $domain = $_POST['domain'];
      $data = json_decode($jsonContents, true);
      $last_item = end($data);
      $last_item_id = $last_item['id'];
      $data[] = array(
          'name' =&gt; $name,
          'domain' =&gt; $domain,
          'id' =&gt; $last_item_id+1
      );
      $json = json_encode($data);
      file_put_contents('data/data.json', $json);
      return $this-&gt;response-&gt;withRedirect('../index.html');
  });
  </code></pre>