在GAE Python中从AJAX调用获得响应的问题

时间:2012-11-17 21:01:59

标签: jquery python ajax google-app-engine

我只是想点击一个按钮来简单的ajax调用,使用ajax从文本框中传递一些数据,并在ajax调用后检索相同的内容。但是有些东西在这里很乱,没有任何数据的警告< / p>

这是我的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()

1 个答案:

答案 0 :(得分:2)

您的AJAX调用根本不包含inputData查询字段。更新您的jQuery $.ajax() data参数:

data: { inputData: vdata },