admin管理员组文章数量:1316004
I am working on a Django project and I am sending a post request via Jquery's ajax method. The csrftoken has been retrieved from the browsers cookie with javascript.
$.ajax({
type : 'POST',
beforeSend: function( xhr, settings){
xhr.setRequestHeader("X-CSRFToken", csrftoken );
},
url : '/endpoint/',
data : { 'requestParam': [1,2,3,4] }
}).done(function(d) {
callback(d);
});
Then I check what the backend receives via the ajax call;
print( request.POST )
I was expecting this;
<QueryDict: {u'requestParam': [u'1', u'2', u'3', u'4']}>
Instead I get this;
<QueryDict: {u'requestParam[]': [u'1', u'2', u'3', u'4']}>
Which seems odd. Where did the '[]' extra in the key name e from? Is this a convention that is handled this way in Django or is this something that AJAX does when sending lists?
I am working on a Django project and I am sending a post request via Jquery's ajax method. The csrftoken has been retrieved from the browsers cookie with javascript.
$.ajax({
type : 'POST',
beforeSend: function( xhr, settings){
xhr.setRequestHeader("X-CSRFToken", csrftoken );
},
url : '/endpoint/',
data : { 'requestParam': [1,2,3,4] }
}).done(function(d) {
callback(d);
});
Then I check what the backend receives via the ajax call;
print( request.POST )
I was expecting this;
<QueryDict: {u'requestParam': [u'1', u'2', u'3', u'4']}>
Instead I get this;
<QueryDict: {u'requestParam[]': [u'1', u'2', u'3', u'4']}>
Which seems odd. Where did the '[]' extra in the key name e from? Is this a convention that is handled this way in Django or is this something that AJAX does when sending lists?
Share Improve this question asked Jan 9, 2014 at 9:46 cantdutchthiscantdutchthis 34.7k17 gold badges77 silver badges116 bronze badges1 Answer
Reset to default 13This is jQuery believing that everyone in the world uses PHP.
Add traditional: true
to your ajax
object.
本文标签: javascriptjquery ajax post list appends 3939 to querydict in djangoStack Overflow
版权声明:本文标题:javascript - jquery ajax post list appends '[]' to querydict in django - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741995437a2409946.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论