I am testing code with Python and Javascript trying to set up an Ajax system. Basically, I just want to enter a word and return the Python code. Here is my html / javascript:
<html> <head> <title>Simple Ajax Example</title> <script language="Javascript"> function xmlhttpPost(strURL) { var xmlHttpReq = false; var self = this; </script> </head> <body> <form name="f1"> <p>word: <input name="word" type="text"> <input value="Go" type="button" onclick='JavaScript:xmlhttpPost("/ajaxtest")'></p> <div id="result"></div> </form> </body> </html>
and here is my python:
class AjaxTest(BlogHandler): def get(self): user = self.get_user() self.render('ajaxtest.html', user = user) def post(self): user = self.get_user() word = self.request.get('w') logging.info(word) return '<p>The secret word is' + word + '<p>'
When I register a word, it displays correctly and when I hardcode str:
function updatepage(str){ document.getElementById("result").innerHTML = str; }
It displays this correctly, but right now without hardcoding it is not showing anything. How should I send a response? I use webapp2 as my Python infrastructure and Jinja2 as a template engine, although I don't think this is related to this. Do I need to send HTTP headers?
source share