title: Giving variables from html to python
body: <p>I want to give variables from html to python using javascript.</p>
  
  <p>On clicking navbar coded as:</p>
  
  <pre><code>aa.html      
     &lt;a href="{{url_for('to_python')}}" id='aa'&gt;hello&lt;/a&gt;
  </code></pre>
  
  <p>Where <code>to_python</code> route goes to <code>bb.html</code></p>
  
  <p>I want to pass variable <code>animal='dog'</code> when clicking on aa.html href.</p>
  
  <hr>
  
  <p>I tried using </p>
  
  <pre><code>$("#aa").attr("href", '?animal=dog')
  </code></pre>
  
  <p>But this does not go to bb.html.
  The result is <code>aa.html?animal=dog</code> ( I want <code>bb.html?animal=dog</code>)</p>
  
  <hr>
  
  <p>※Also I would like to know a way to pass variables on method <code>POST</code> using javascript. Any Ideas?</p>
  
  <hr>
  
  <p>I tried using </p>
  
  <pre><code>$('#aa').on("click", function(){
    $.post('/to_python', {animal:'dog'}, function(res){
    .....something
    }
  </code></pre>
  
  <p>But this code sometime work, but sometimes not. Do not know what is wrong.</p>