title: Problems with ajax and session variable in Web2Py
body: <p>I'm developing an app in Web2Py that consists in a little e-commerce. Have a controller and page that the link is localhost:8000/topranchos/produto, with products, were topranchos is the app.</p>
  
  <p>In the page produto there are a list of products like this:</p>
  
  <p><a href="http://i.stack.imgur.com/5Fs5G.png" rel="nofollow">The image is in this link</a></p>
  
  <p>When the button "Adicionar ao carrinho" is clicked, the javascript function is executed:</p>
  
  <pre><code>&lt;script&gt;
      function adicionarCarrinho(prod, qtde) {
          quantidade = document.querySelector(qtde).value
          console.log(quantidade)
        if(quantidade &gt; 0) {
            $.get("{{=URL(f="adicionarCarrinho")}}", {produto: prod, qtde: quantidade} )
              .done(function( data ) {
                  console.log (data)
                  var atual =document.querySelector(".badge-carrinho").innerHTML;
                  document.querySelector(".badge-carrinho").innerHTML =
                  parseInt(quantidade) + parseInt(atual);
                  alert("Adicionado ao carrinho com sucesso");
                  });
          }
          else alert("Selecione a quantidade de itens deste produto que você deseja");
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>It's make a requisition to the action default/adicionarCarrinho:</p>
  
  <pre><code>def adicionarCarrinho():
  if request.vars:
      session.carrinho.append(
      #{'produto':db(db.produto.id == request.vars['produto']).select(),
      {'produto':int(request.vars['produto']),
      'quantidade':int(request.vars['qtde'])}
      )
      print "----------"
      print session.carrinho
      return str("OK")
  </code></pre>
  
  <p>Where session.carrinho have a list that was declared on db.py model:</p>
  
  <pre><code>#carrinho
  session.carrinho = []
  </code></pre>
  
  <p>On the terminal, the command print session.carrinho print the item received by the ajax request, but when I add other itens the list is empty. When I click on the page of carrinho, that shows the session.carrinho's informations, the var is empty.</p>
  
  <p>How can I repair this? I tried use cookies of course Web2Py book, but I dummie on Web2Py and not has success yet :/</p>
  
  <p>thank you!</p>