[Django]-Unable to retrieve an Array of objects posted to Django from jQuery

6👍

You need to encode the JavaScript objects first. Those cannot be passed directly via GET or POST parameters.

Try calling JSON.stringify() on the JavaScript objects before you POST it with jQuery (that is, the arbitrary data enclosed with { "size":"3", "color":"1" ... }). For example:

[

    JSON.stringify({
        "size":"2",
        "color":"1",
        "colorNumber":"1",
        "barCode":"1234567890",
        "barCodePic":"",
    }),
    JSON.stringify({
        "size":"3",
        "color":"1",
        "colorNumber":"2",
        "barCode":"0987654321",
        "barCodePic":"",
    })

]

Then within Python, use something like to decode it:

import json
box_0_string = request.POST.get('boxes[]')[0]
box_0_dict = json.loads(box_0_string)

To get the individual JSON objects.

Leave a comment