简体   繁体   中英

Sending a javascript array to django views

I have the following javascript array at the client side -

["27", "28", "29", "30"] 

I am sending it to server as follows -

$.post(
  '/save/mempks/1/',
  {'data':elmArry},
  function(data){alert(data);});

On the server, I have put a debugger to see how, the data is received, and I see this unusual behaviour -

ipdb> request.POST
<QueryDict: {u'data[]': [u'27', u'28', u'29', u'30']}>

ipdb> request.POST.items()
[(u'data[]', u'30')]

ipdb> request.POST['data[]']
u'30'

All I want to do is extract, the numbers 27 to 30 and save it in a list.

Where are the numbers 27, 28, 29, and 30 are getting lost?

Could anyone suggest, why this behavior?

in case of posting list use request.POST.getlist('key') to get data. If you would use some kind of form for picking up posted data, then it would do it for you. https://docs.djangoproject.com/en/dev/ref/request-response/#id3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM