ボタンをクリックするだけで単純なajax呼び出しを行い、ajaxを使用してテキストボックスからデータを渡し、ajax呼び出し後に同じものを取得しようとしていますが、ここではデータがないアラートが発生するため、何かが厄介です。
これが私のajaxTest.htmlです
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"
type="text/javascript">
</script>
<script>
function getData() {
var vdata = $('#txt').val();
$.ajax({
type: "GET",
url: "/processAjax",
data: vdata,
success: function (responseText) {
alert(responseText);
}
});
}
</script>
</head>
<body>
<input id="txt" type="textbox" runat="server" />
<input type="button" runat="server" onclick="getData();" />
</body>
</html>
これが私のmain.pyです
import httplib2
import os
class AjaxCall(webapp.RequestHandler):
def get(self):
template_data = {}
template_path = 'ajaxTest.html'
self.response.out.write(template.render(template_path,template_data))
class ProcessAjax(webapp.RequestHandler):
def get(self):
inputdata = self.request.get("inputData")
self.response.out.write(inputdata)
application = webapp.WSGIApplication(
[('/processAjax',ProcessAjax),
('/ajaxPage',AjaxCall)
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()