title: passing variable from twig JavaScript $.ajax to Symfony2 controller
body: <p>(I've simplified the previous question)
  I need to pass variable to Symfony2 controller using JavaScript, set that variable to session and then return session variable. </p>
  
  <pre><code>//test1.html.twig with $.ajax script and &lt;input&gt; tag.
  
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;form action="#" method="#"&gt;
      &lt;input type="number" class="inputISBN" name="name" 
           value="666" onchange="myFunction()"&gt;
  &lt;/form&gt;
  
  &lt;script type='text/javascript'&gt;
  function myFunction() {
     var elementy = document.getElementsByClassName('inputISBN');
     var data = elementy[0].getAttribute('value');
  
     $.ajax({
          url: "{{ path('test') }}",
          type: "POST",
          data: data ,
          success: function() {alert("ok");}
      });   
  }
  &lt;/script&gt;    
  </code></pre>
  
  <p>Here are Actions in Controller:</p>
  
  <pre><code>/**
   * @Route("/test1", name="test1")
   * @Template()
   */
  public function test1Action()
  {        
       return array();          
  }
  
  
  /**
   * @Route("/test", name="test")
   * @Template()
   */
  public function testAction(Request $request)
  {
      $data = $request-&gt;request-&gt;get('data');        
      $session = $request-&gt;getSession();    
      $session-&gt;set('data',$data );
      return array();
  }
  
  
   /**
   * @Route("/test2", name="test2")
   * @Template()
   */
  public function test2Action(Request $request)
  {       
      $session = $request-&gt;getSession();    
      $data = $session-&gt;get('data');        
      echo '&lt;pre&gt;',print_r($data),'&lt;/pre&gt;';         
      return array();
  }
  </code></pre>
  
  <p>I'm getting alert('ok') when changing value in input tag, but when opening test2Action site print_r($data) returns just 1.</p>