views:

19

answers:

1

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'}?

A: 

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.

Java Drinker
bummer. thanks anyways.
rotrotrot