I currently have the following javascript array:
var stuffs = ['a', 'b'];
I pass the above to the server code using jQuery’s load:
var data = {
'stuffs': stuffs
};
$(".output").load("/my-server-code/", data, function() {
});
On the server side, if I print the content of request.POST(I’m currently using Django), I get:
'stuffs[]': [u'a', u'b']
Notice the [] at the prefix of the variable name stuffs. Is there a way to remove that [] before it reaches the server code?
This is default behavior in jQuery 1.4+…if you want the post to be
&stuffs=a&stuffs=binstead of&stuffs[]=a&stuffs[]=byou should set thetraditionaloption totrue, like this:Note this affects all requests… which is usually what you want in this case. If you want it to be per-request you should use the longer
$.ajax()call and settraditional: truethere. You can find more info abouttraditionalin the$.param()documentation.