Javascript jQuery通过ajax向django视图提交js对象
如何通过jQuery向django提交javascript对象Javascript jQuery通过ajax向django视图提交js对象,javascript,jquery,django,Javascript,Jquery,Django,如何通过jQuery向django提交javascript对象 $.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():
$.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']}>
def fetch_项目(请求):
if request.is_ajax():
打印请求.POST
#输出
>>>
为什么“foobar[spam]”是一个键,而“foobar”不是dict的键{“spam”:“eggs”}?请参阅以下讨论:
似乎可以通过递归/深度嵌套导致溢出。默认情况下,Django很可能正在防范这种情况