title: Passing a string from Python to Javascript
body: <p>I'm trying to pass a string from Python to Javascript via ajax POST request but i'm finding serious difficulties.</p>
  
  <p>I've tried both with and without using JSON.</p>
  
  <p>Here's the code</p>
  
  <p><strong>JAVASCRIPT</strong></p>
  
  <pre><code>$.ajax({
      url: url, #url of the python server and file
      type: "POST",
      data: {'data1': "hey"},
      success: function (response) {
          console.log(" response ----&gt; "+JSON.parse(response));
          console.log(" response no JSON ---&gt; " +response);
      },
      error: function (xhr, errmsg, err) {
          console.log("errmsg");
      }
  });
  </code></pre>
  
  <p><strong>Python</strong></p>
  
  <pre><code>import json
  print "Access-Control-Allow-Origin: *";
  if form.getvalue("data1") == "hey":
        out = {'key': 'value', 'key2': 4}
        print json.dumps(out)
  </code></pre>
  
  <p>Result is a empty JSON. when i do something like JSON.parse in javascript I get a unexpected end of input error, and when i try to get the length of the response data the size I get is 0.
  I suppose that there should be some problems with the client server communication (I use a CGIHTTPServer) or maybe something wrong with the datatype that python or javascript expects.</p>
  
  <p>I also tried without JSON, with something like
  Python </p>
  
  <pre><code> print "heyyyyy"
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code> alert(response) //case of success
  </code></pre>
  
  <p>but I also got an empty string.</p>
  
  <p>Could you please give me some advices for handling this problem ? 
  Thanks a lot!</p>