title: Cakephp with ajax post request get error
body: <p>I have in Cakephp a form which is loaded by an ajax request. After sending the form via another ajax request, the magic is done in the controller and the controller is sending back new html code. So far so good. It works pretty well as long as I send a get request. If I change the ajax script to force a post request, the result is blackholed. I read a lot about the security component and tried to change a lot of things, but it does not work.</p>
  
  <p>Here is my code of the "OffersController.php":</p>
  
  <pre><code>App::uses('AppController', 'Controller');
  App::uses('Folder', 'Utility');
  App::uses('File', 'Utility');
  
  
  class OffersController extends AppController {
  
  public $components = array('Paginator');
  
  
  public function beforeFilter() {
      parent::beforeFilter();
      $this-&gt;Auth-&gt;allow('createform');
      $this-&gt;Security-&gt;unlockedActions = array('createform');
  }
  
  
  public function createform() {
      $this-&gt;request-&gt;onlyAllow('ajax'); // No direct access via browser URL
      //$this-&gt;autoRender = 'false; // We don't render a view in this example
      $this-&gt;Security-&gt;validatePost = false;
      if ($this-&gt;request-&gt;is('post')) {
          $this-&gt;Session-&gt;setFlash(__('Post sent.').' &lt;tt class="pull-right"&gt;(C:Offers, F:createform, A:2)&lt;/tt&gt;', 'default', array('class' =&gt; 'alert alert-success'));
      } else {
  
      }
  
      $this-&gt;layout = false;
      $this-&gt;render('offerform');
  }
  
  }
  </code></pre>
  
  <p>And this is the "createform.ctp" which will be loaded through ajax (if the page is loaded and then if the ajax request is sent:</p>
  
  <pre><code>        &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-lg-12 text-center"&gt;
                  &lt;h2 class="section-heading"&gt;Offerte&lt;/h2&gt;
                  &lt;h3 class="section-subheading text-muted"&gt;Fordere unverbindlich eine Offerte an.&lt;/h3&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-lg-12"&gt;
                  &lt;?php echo $this-&gt;Form-&gt;create('Offers', array('name' =&gt; 'Offer', 'action' =&gt; 'createform', 'role' =&gt; 'form', 'type' =&gt; 'post', 'id' =&gt; 'ajaxForm')); ?&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-md-8"&gt;
                              &lt;?php
  
                                  echo $this-&gt;Form-&gt;input('firstname', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Vorname'));
                                  echo $this-&gt;Form-&gt;input('lastname', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Nachname'));
                                  echo $this-&gt;Form-&gt;input('address', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Adresse'));
                                  echo $this-&gt;Form-&gt;input('zip', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Postleitzahl'));
                                  echo $this-&gt;Form-&gt;input('city', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Ort'));
                                  echo $this-&gt;Form-&gt;input('country', array('options' =&gt; array('CH' =&gt; 'Schweiz', 'DE' =&gt; 'Deutschland', 'AT' =&gt; 'Österreich'), 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'before' =&gt; '', 'between' =&gt; '', 'after' =&gt; ''));
                                  echo $this-&gt;Form-&gt;input('emailaddress', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Emailadresse'));
                                  echo $this-&gt;Form-&gt;input('telephone', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Telefonnummer'));
                                  echo $this-&gt;Form-&gt;input('desireddate', array('type' =&gt; 'text', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'gewünschter Reinigungstermin'));
  
                                  $feesarray = Configure::read('feesarray');
                                  $currency = 'CHF';
                                  $optionroom['0'] = 'Anzahl Zimmer / Preis';
                                  foreach($feesarray as $key =&gt; $val) {
                                      $value = $key.' Zimmer / '.$currency.' '.$val[$currency];
                                      $optionroom[$value] = $value;
                                  }
                                  echo $this-&gt;Form-&gt;input('rooms', array('options' =&gt; $optionroom, 'label' =&gt; false, 'div' =&gt; 'form-group col-md-6', 'class' =&gt; 'form-control', 'before' =&gt; '', 'between' =&gt; '', 'after' =&gt; ''));
  
                              ?&gt;
                          &lt;/div&gt;
                          &lt;div class="col-md-4"&gt;
                              &lt;?php echo $this-&gt;Form-&gt;input('message', array('type' =&gt; 'textarea', 'label' =&gt; false, 'div' =&gt; 'form-group col-md-12', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Nachricht')); ?&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="clearfix"&gt;&lt;/div&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-lg-12 text-center"&gt;
                              &lt;p&gt;&amp;nbsp;&lt;/p&gt;
                              &lt;?php
                                  $formButtonOptions = array(
                                      'type' =&gt; 'submit',
                                      'id' =&gt; 'btnSave',
                                      'div' =&gt; false,
                                      'class' =&gt; 'btn btn-xl'
                                  );
                                  echo $this-&gt;Form-&gt;button(__('Offerte anfordern'), $formButtonOptions);
                              ?&gt;
                              &lt;p&gt;&amp;nbsp;&lt;/p&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;?php echo $this-&gt;Form-&gt;end(); ?&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;script&gt;
          $(function () {
              $("#btnSave").click(function(e){
              //$("#ajaxForm").submit(function(e){
                  e.preventDefault(); // avoid to execute the actual submit of the form.
                  var formData = $(this).serializeArray();
                  var formURL = $(this).attr("action");
                  $('#ajaxLoadForm').html('&lt;?php echo __('loading ...'); ?&gt;');    // has to be placed after the var formData, because the form gets replaced after this line...
  
                  $.ajax({
                      type: "post",
                      cache: false,
                      dataType: "html",
                      data: formData,
                      //processData: true,
                      url: formURL,
                      success: function (data, textStatus, jqXHR) {
                          // replace div's content with returned data
                          $('#ajaxLoadForm').html(data);
                      },
                      error: function(jqXHR, textStatus, errorThrown) {
                          alert("An error occurred: " + jqXHR.responseText.message);
                          console.log(jqXHR);
                      }
                  });
  
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>And this is my Model "Offer.php":</p>
  
  <pre><code>class Offer extends AppModel {
  public $name = 'Offer';
  
  }
  </code></pre>
  
  <p>Thank you for any help and hints. Any ideas?</p>