How do I submit a javascript object via jQuery to django?
$.ajax({
type: 'POST',
url: '/fetch-items/',
data: {'foo': 'bar', 'foobar': {'spam': 'eggs'} },
success: function(){
alert('yey');
}
});
django part:
def fetch_items(request):
if request.is_ajax():
开发者_开发知识库print request.POST
#output
>>> <QueryDict: {u'foo': [u'bar'], u'foobar[spam]': [u'eggs']}>
Why is 'foobar[spam]' a key and not 'foobar' a key to a dict {'spam': 'eggs'}?
See this discussion:
http://markmail.org/message/6vk66gsfyc2eiesb
Seems you can cause an overflow by recursive/deep nesting. Likely Django is protecting against this by default.
精彩评论