[Answer]-Django ajax passing variable to the views

1👍

The error message shows what is wrong – you’re looking up a key ages, but you’re sending something called ages[] with some extra square brackets.

If you’ve put those brackets in the field name, you don’t need them – that’s a PHP-ism. (It might not be your fault: jQuery has been known to do add them itself.) In any case, you’ll want to use request.POST.getlist(fieldname) to get the list of multiple values associated with that key.

Leave a comment