title: Symfony 2: JQuery Ajax, Gets 500 internal server error
body: <p>I am using jquery ajax for a certain functionality like user clicks on the "Get Code" button , ajax request is made to one of the symfony2 controller action. When I try it am getting 500 internal error when i check the firebug console.</p>
  
  <p>Here's the ajax code(Using FOSJsRoutingBundle):</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function () {
      var locale = '{{ app.request.get('_locale') }}';
      $('.codeBtn').click(function(){
          $.ajax({
            url: Routing.generate('gd_getcode',{ '_locale': locale}),
            success: function(html){
              alert("Successful Response from server");
            }
          });
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>Here's my controller action:</p>
  
  <pre><code>public function getCodeAction()
  {
      if ($this-&gt;container-&gt;get('request')-&gt;isXmlHttpRequest()) {
          $code = rand(1,9999);
          $this-&gt;getUser()-&gt;setAttribute('transactionCode', $code);
  
          $message = \Swift_Message::newInstance()
                      -&gt;setSubject("Code")
                      -&gt;setFrom('info@mymail.com')
                      -&gt;setTo('mymail@email.com')
                      -&gt;setBody($code);
                  $this-&gt;get('mailer')-&gt;send($message);
  
          return true;
  
      }
  
  }
  </code></pre>
  
  <p>Is anything wrong in my code or am i missing any of the ajax settings parameters.</p>