title: send JSON Object via POST or AJAX JQuery to PHP
body: <p>I checked many answers for my question but none of them worked for me.
  I created an <code>json</code> object with a <code>script</code> that i found in <code>stackoverflow</code>, and works fine, but when i try to send it to <code>php</code> (i use <strong><em>laravel framework</em></strong>) with <code>$.post</code>, the <code>var_dump</code> of object <code>returns NULL</code>.<br><br>
  In <em>Network tab of Chrome Debug</em>, the <code>POST request</code> has gone good but <code>php</code> can't get any data.
  I have already used <code>POST Ajax</code> in this project without problems except this.</p>
  
  <p><strong>How i can send my Object correctly to PHP?</strong></p>
  
  <p>There is a JQuery script that get form values and convert them in JSON Object:</p>
  
  <pre><code>jQuery.fn.serializeObject = function() {
      var arrayData, objectData;
      arrayData = this.serializeArray();
      objectData = {};
  
      $.each(arrayData, function() {
          var value;
  
          if (this.value !== '') {
              value = this.value;
  
              if (objectData[this.name] != null) {
                  if (!objectData[this.name].push) {
                      objectData[this.name] = [objectData[this.name]];
                  }
  
                  objectData[this.name].push(value);
              } else {
                  objectData[this.name] = value;
              }
          }
      });
  
      return objectData;
  };
  </code></pre>
  
  <p><strong>EDIT 2: this is the two method i'm using to resolve the problem:</strong></p>
  
  <pre><code>$('#details_form').on('submit',function(e){
  
  e.preventDefault();
  var json_enc = JSON.stringify($('#details_form').serializeObject());
  
  $.post(
          $("#details_form").prop('action'), 
          { 'json_enc' : json_enc }, 
          function(data) 
          { alert(data.msg) }, 'json'); });
  </code></pre>
  
  <p><strong>2nd method without JSON:</strong></p>
  
  <pre><code>$('#save').on('click',function(e) {
  
  var form = $(this).closest('form') ;
  e.preventDefault();
  
  var result = form.serialize();
  
  var ajax = $.post(
      form.data('action'),        {
          'data': result
      },
      function(data) {
          alert(data);
      }
  );
  
  ajax.fail(function(data){
      alert('fail (see console for details)') ;
      console.log(data) ;
  }) ;
  </code></pre>
  
  <p>})</p>
  
  <p><strong>The first function returns this JSON Object:</strong></p>
  
  <pre><code>{
      "_token": "HeC6RwznFYuemIvP68pHYuET634fgQoZQCtL7ed3",
      "id": "contact_1",
      "name": "John",
      "surname": "Wayne",
      "address": "2nd street",
      "contact": ["656346843", "56196856"]
  }
  </code></pre>
  
  <p><strong>The second function returns:</strong></p>
  
  <pre><code>_token=HeC6RwznFYuemIvP68pHYuET634fgQoZQCtL7ed3&amp;id=contact_1&amp;name=Gino&amp;surname=Megna&amp;address=kjwebgflk+645&amp;contact=656346843&amp;contact=6548198189&amp;contact=
  </code></pre>
  
  <p>With both JQuery functions, returns in PHP (with var_dump($_POST)):</p>
  
  <pre><code>array(6) { ["_token"]=&gt; string(40) "HeC6RwznFYuemIvP68pHYuET634fgQoZQCtL7ed3" ["id"]=&gt; string(9) "contact_1" ["name"]=&gt; string(4) "Gino" ["surname"]=&gt; string(5) "Megna" ["address"]=&gt; string(13) "kjwebgflk 645" ["contact"]=&gt; string(0) "" }
  </code></pre>
  
  <p>This is my form:</p>
  
  <pre><code>&lt;form method="POST" action="http://localhost/rubrica/public/contact_process" accept-charset="UTF-8" class="form-bootstrap" id="details_form" autocomplete="off"&gt;
  &lt;input name="_token" type="hidden" value="HeC6RwznFYuemIvP68pHYuET634fgQoZQCtL7ed3"&gt;
  &lt;input id="contact_id" name="id" type="hidden" value="contact_1"&gt;
  &lt;div class="bg_contact"&gt;
      &lt;div class="image_contact"&gt;
          &lt;label for="immagine" id="" class=""&gt;Add Image&lt;/label&gt;
          &lt;input name="image" type="file" id="immagine"&gt; &lt;/div&gt;
      &lt;div class="rif_contact"&gt;
          &lt;div class="name_contact"&gt;
              &lt;input placeholder="Name" id="name" name="name" type="text" value="John"&gt; &lt;/div&gt;
          &lt;div class="surname_contact"&gt;
              &lt;input placeholder="Surname" id="surname" name="surname" type="text" value="Wayne"&gt; &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="address"&gt;
      &lt;div class="label_address"&gt;
          &lt;label for="address"&gt;Address&lt;/label&gt;
      &lt;/div&gt;
      &lt;input placeholder="Address" id="address" name="address" type="text" value="2nd street"&gt; &lt;/div&gt;
  &lt;div class="bg_details"&gt;
      &lt;label for="contacts"&gt;Contacts&lt;/label&gt;
      &lt;div class="content_detail"&gt;
          &lt;input type="text" name="contact" class="contact_details" placeholder="Telephone" value="656346843" id="detail_161"&gt;
          &lt;button onclick="delete_detail_exist(this,161)" id="remScnt" type="button"&gt;Remove&lt;/button&gt;
      &lt;/div&gt;
      &lt;div class="content_detail"&gt;
          &lt;input type="text" name="contact" class="contact_details" placeholder="Telephone" value="56196856" id="detail_160"&gt;
          &lt;button onclick="delete_detail_exist(this,160)" id="remScnt" type="button"&gt;Rimuovi&lt;/button&gt;
      &lt;/div&gt;
      &lt;div class="content_detail"&gt;
          &lt;input placeholder="Telephone" class="contact_details" id="p_scnt" name="contact" type="text"&gt;
          &lt;button id="addScnt" onclick="add_detail_field(this)" type="button"&gt;Add&lt;/button&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;input id="save" type="submit" value="Save"&gt; &lt;/form&gt;
  </code></pre>
  
  <p>PHP Method:</p>
  
  <pre><code>public function contact_process() {
      $result = trim (Input::get('result'));
      $json = json_decode($result);
      var_dump($json);
  }
  </code></pre>