iJade
iJade

Reputation: 23811

Issue getting response from AJAX call in GAE Python

I'm just trying to make a simple ajax call on click of a button to pass some data from a textbox using ajax and retrieve the same after ajax call.But some thing is messy in here causin an alert without any data

Here is my 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>

Here is my 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()

Upvotes: 2

Views: 466

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124548

Your AJAX call doesn't include a inputData query field at all. Update your jQuery $.ajax() data parameter:

data: { inputData: vdata },

Upvotes: 2

Related Questions