title: Send POST Data with Ajax, withtout form, to a Symfony2 Controller, in JSON format
body: <p>Good evening everybody!</p>
  
  <p>I would like to send JSON Post Data to a Symfony Controller <strong>without form</strong>, but it doesn't work. I build a JSON data line and <strong>it is well built</strong>, it is <strong>NOT</strong> the problem. When I send my data with AJAX, <strong>the request is not filled</strong>.</p>
  
  <p>Here is my Javascript code:</p>
  
  <pre><code>function validerSession()
  {
      //I don't describe the composition of the dataline.
      var dataObject = JSON.stringify(obj); //My dataline JSONified
  
      $.ajax({
          type: "POST",
          url: Routing.generate('cloud_money_drop_validerSession', { id: {{ partie.id }}, idSession: sessionId }),
          data: dataObject,
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function (donnees) {
              alert("Hello");
          }
      });
  }
  </code></pre>
  
  <p><strong>The AJAX call work.</strong></p>
  
  <p>Here is the PHP Symfony Controller method which received data:</p>
  
  <pre><code>public function validerSessionAction(Partie $partie, Session $session)
  {
      $request = $this-&gt;get('request');
      $data = json_decode($request-&gt;getContent());
  
      $serializer = $this-&gt;container-&gt;get('jms_serializer');
      $response = $serializer-&gt;serialize($data, 'json');
      return new Response($response);
  }
  </code></pre>
  
  <p>But <strong>there is not any data in <code>$data</code></strong>.</p>
  
  <p><strong>EDIT</strong> : An example of the dataline JSONified</p>
  
  <p><code>{"trappes":{"1":{"id":"134","montant":"5000"},"2":{"id":"135","montant":"15000"},"3":{"id":"136","montant":"20000"},"4":{"id":"137","montant":"0"}}}</code></p>
  
  <p>Do you have any idea ? I'm sure this is a common issue.
  Thank you for your participation !</p>
  
  <p>CloudCompany</p>