How can I get json data from ajax?

473 views
Skip to first unread message

Kevin Jiang

unread,
Nov 1, 2012, 11:18:10 PM11/1/12
to we...@googlegroups.com
Hi Guys,

I use jQuery post the json data like this:

postData = {'id': 12, 'data': [{'name': 'myname', 'value': 'myvalue'}, {'name': 'myname2', 'value': 'myvalue2'}]};
$.post(url, postData, function(){});

At the backend, I got the post data like following use web.input():
postData = web.input()
print postData

<Storage {'data[0][name]': u'myname', 'data[0][value]': u'myvalue', 'data[1][name]': u'myname2', 'data[1][value]': u'myvalue2', 'id': u'12'}>

I only can get postData.id, how can get the data list directly.

Thanks.

Kevin Houlihan

unread,
Nov 2, 2012, 1:49:30 PM11/2/12
to we...@googlegroups.com
Hi Kevin,

Maybe you could try using web.data() instead of web.input(). You would then need to parse this using the json parser from the standard library.

import json

postData = web.data()
parsedData = json.loads(postData)

--
You received this message because you are subscribed to the Google Groups "web.py" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/ozmmfxgOuYIJ.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.

Reply all
Reply to author
Forward
0 new messages