PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 6, 2022

[FIXED] How to get an array in Django posted via Ajax

 September 06, 2022     ajax, django, jquery, python-2.7     No comments   

Issue

When I try to send an array to Django via Ajax (jQuery)

JavaScript code:

new_data = ['a','b','c','d','e'];
$.get('/pythonPage/', {'data': new_data},function(data){});

and I try to read the array:

Python:

request.GET.get("data[]")

I get only the last array value:

'e'

What am I doing wrong?


Solution

You're looking for the QueryDict's getlist

request.GET.getlist('data')
request.GET.getlist('data[]')
request.GET.getlist('etc')

https://docs.djangoproject.com/en/2.0/ref/request-response/#django.http.QueryDict.getlist



Answered By - Yuji 'Tomita' Tomita
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing