开发者

jQuery submit a js object via ajax to django view

开发者 https://www.devze.com 2023-01-10 05:14 出处:网络
How do I submit a javascript object via jQuery to django? $.ajax({ type: \'POST\', url: \'/fetch-items/\',

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消