Search code examples
google-app-enginecoffeescriptwebapp2

How to pass a list value to a webapp2 backend via $.post?


In my coffeescript frontend I attempt to pass a list of value to the backend

data = {
  id: [2, 3, 4]
}

$.post url, data

In the handler in a Google app engine (python) backend, I read the value like so:

    id_value = self.request.get('id')

    LOG.info("%s", id_value)

It always print out '2' only.

How can I get the backend to obtain the list [2,3,4]?


Solution

  • $.post by default sends data in url-encoded format, which handles nested structures in its own way.

    You might need to encode the data in JSON before sending and then decode it on the server side - an example is here.