title: Call python function from JS
body: <p>I am trying to call a function in Python from my JavaScript code. I used the code explained <a href="https://stackoverflow.com/questions/13175510/call-python-function-from-javascript-code">here</a> but it does not work for me.</p>
  
  <p>Here is my JS code: </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;body&gt;
  &lt;script type="text/javascript" src="d3/d3.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"&gt;&lt;/script&gt;  
  &lt;script&gt;
  text ="xx";
  
  $.ajax({
  type: "POST",
  url: "~/reverse_pca.py",
  data: { param: text}
  }).done(function(o) {
      console.log(data);
      console.log(text);
  });
  </code></pre>
  
  <p></p>
  
  <p>Python Code:</p>
  
  <pre><code>import csv
  from numpy import genfromtxt
  from numpy import matrix
  
  def main():
      ...
      return x 
  if __name__ == "__main__":
      x=main()
      return x;
  </code></pre>
  
  <p>Do you know what is wrong with it?</p>