title: cakephp 3.8 store ajax data in database
body: <p>I am trying to store ajax data into the database in cakephp 3.8.</p>
  
  <p>The data looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/WNLT7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WNLT7.png" alt="enter image description here"></a></p>
  
  <p>The data stands for 2 checked checkboxes, with hidden inputs.</p>
  
  <p>I am using the following ajax code:</p>
  
  <pre class="lang-js prettyprint-override"><code>var formData = menuItem;
  
  var formUrl = $('#nav-menu-meta').attr('action');
  
  $.ajax({
      type: 'POST',
      url: formUrl,
      data: formData,
      success: function(response,textStatus,xhr) {
          console.log('test ', response);
  
      },
      error: function(xhr,textStatus,error) {
          console.error(textStatus, error);
      }
  });
  </code></pre>
  
  <pre><code>public function addmenuitems() {
      if ($this-&gt;request-&gt;is('ajax')) {
          $this-&gt;autoRender = false;
          $this-&gt;response-&gt;disableCache();
      }
  
      if ($this-&gt;request-&gt;is('post')) {
  
          $menuitemTable = TableRegistry::getTableLocator()-&gt;get('menuitems');
          $menuitems = $menuitemTable-&gt;newEntities($this-&gt;request-&gt;getData());
  
          foreach ($menuitems as $menuitem) {
              if ($menuitemTable-&gt;save($menuitem)) {
                  $response = $this-&gt;response-&gt;withType('application/json')
                      -&gt;withStringBody(json_encode($menuitem));
                  return $response;
              }else{
                  $message = 'Error';
              }
          }            
      }
  }
  </code></pre>
  
  <p>The data is not saved at all, so what am I missing?</p>
  
  <p>I added the debug data array from the getData() function to show what the array contain:</p>
  
  <pre><code>/src/Controller/Admin/Web/MenusController.php (line 109)
  [
      (int) 0 =&gt; object(App\Model\Entity\MenuItem) {
  
          'menu_item_object_id' =&gt; (int) 2,
          'menu_item_title' =&gt; 'Home',
          'menu_item_slug' =&gt; 'home',
          'menu_item_parent_id' =&gt; (int) 0,
          'menu_item_target' =&gt; false,
          'menu_item_position' =&gt; (int) 0,
          '[new]' =&gt; true,
          '[accessible]' =&gt; [
              '*' =&gt; true,
              'id' =&gt; false,
              'menu-item-object_id' =&gt; true,
              'menu-item-parent_id' =&gt; true,
              'menu-item-position' =&gt; true,
              'lft' =&gt; true,
              'rght' =&gt; true,
              'menu-item-title' =&gt; true,
              'menu-item-slug' =&gt; true,
              'menu-item-target' =&gt; true
          ],
          '[dirty]' =&gt; [
              'menu_item_object_id' =&gt; true,
              'menu_item_title' =&gt; true,
              'menu_item_slug' =&gt; true,
              'menu_item_parent_id' =&gt; true,
              'menu_item_target' =&gt; true,
              'menu_item_position' =&gt; true
          ],
          '[original]' =&gt; [],
          '[virtual]' =&gt; [],
          '[hasErrors]' =&gt; false,
          '[errors]' =&gt; [],
          '[invalid]' =&gt; [],
          '[repository]' =&gt; 'menuitems'
  
      },
      (int) 1 =&gt; object(App\Model\Entity\MenuItem) {
  
          'menu_item_object_id' =&gt; (int) 3,
          'menu_item_title' =&gt; 'Nieuw',
          'menu_item_slug' =&gt; 'nieuw',
          'menu_item_parent_id' =&gt; (int) 0,
          'menu_item_target' =&gt; false,
          'menu_item_position' =&gt; (int) 0,
          '[new]' =&gt; true,
          '[accessible]' =&gt; [
              '*' =&gt; true,
              'id' =&gt; false,
              'menu-item-object_id' =&gt; true,
              'menu-item-parent_id' =&gt; true,
              'menu-item-position' =&gt; true,
              'lft' =&gt; true,
              'rght' =&gt; true,
              'menu-item-title' =&gt; true,
              'menu-item-slug' =&gt; true,
              'menu-item-target' =&gt; true
          ],
          '[dirty]' =&gt; [
              'menu_item_object_id' =&gt; true,
              'menu_item_title' =&gt; true,
              'menu_item_slug' =&gt; true,
              'menu_item_parent_id' =&gt; true,
              'menu_item_target' =&gt; true,
              'menu_item_position' =&gt; true
          ],
          '[original]' =&gt; [],
          '[virtual]' =&gt; [],
          '[hasErrors]' =&gt; false,
          '[errors]' =&gt; [],
          '[invalid]' =&gt; [],
          '[repository]' =&gt; 'menuitems'
  
      }
  ]
  </code></pre>