title: Calling a Python script from Javascript, both local files
body: <p>I'm trying to run a python script from a local javascript file (part of a locally running HTML/javascript program).</p>
  
  <p>I've been googling this for hours and found a lot of solutions, none of which actually work for me. </p>
  
  <p>Here is the javascript:</p>
  
  <pre><code>$.ajax({
  
      type: "POST",
      url: "test.py",
      data: { param: " "}
      }).done(function( o ) {
          alert("OK");
  });
  </code></pre>
  
  <p>The test.py file is in the same folder as the script/html file. </p>
  
  <p>here is the script:</p>
  
  <pre><code>#!/usr/bin/python
  import os
  filepath = os.getcwd()
  def MakeFile(file_name):
      temp_path = filepath + file_name
      with open(file_name, 'w') as f:
      f.write('''\
  def print_success():
      print "sucesss"        
  ''')
      print 'Execution completed.'
  
  MakeFile("bla.txt");
  </code></pre>
  
  <p>It works fine when run normally. </p>
  
  <p>On my Firefox console I get a "not well formed" error and the script doesn't create a file. However, I can see that Firefox does fetch the script, as I can view it in my browser by clicking the file name.</p>