0
如何通过jQuery提交一个javascript对象到Django?jQuery通过ajax提交一个js对象到Django视图
$.ajax({
type: 'POST',
url: '/fetch-items/',
data: {'foo': 'bar', 'foobar': {'spam': 'eggs'} },
success: function(){
alert('yey');
}
});
Django的部分:
def fetch_items(request):
if request.is_ajax():
print request.POST
#output
>>> <QueryDict: {u'foo': [u'bar'], u'foobar[spam]': [u'eggs']}>
为什么是 'foobar的[垃圾]' 的关键,而不是 'foobar的' 的字典{ '垃圾邮件': '鸡蛋'}的关键?
无赖。不管怎么说,多谢拉。 – rotrotrot 2010-08-03 14:23:53