Read jQuery-posted data in Python App Engine

1k views Asked by At

Suppose I have performed an AJAX call with jQuery in the following fashion:

key = 'boo'
$.ajax({
  type: 'GET',
  async: true,
  url: '/output',
  data: JSON.stringify({'location':key}),
  success: function(data) {
  }
});

I have a route in my Python App Engine code that receives the call on '/output', but how can I get it to access the data I've passed in the AJAX call? That is, how do I fill in the following:

class OutputRoute(webapp.RequestHandler):
  def get(self):
    # something goes here to get the data from above
1

There are 1 answers

4
Moishe Lettvin On BEST ANSWER

Why are you JSON.stringifying your 'data' param? If you don't do that and instead write:

data: {'location': key},

Then in your handler you can just write:

location = self.request.get('location')

jQuery.ajax will take care of turning the object specified in the data parameter into query params (for a GET), and webapp.RequestHandler.request.get parses the query params.