1

I am trying to send list of arrays using ajax post/get and receive it with flask request.

[{  "Amobia at 40 mm (J)": "",
        "Diameter (mm)": "",
        "Thickness (mm)": "",
        "Resin/100 (mm)": ""
    },
    {"Amobia at 40 mm (J)": "",
        "Diameter (mm)": "",
        "Thickness (mm)": "",
        "Resin/100 (mm)": ""
}]

Front-end:

$.ajax({
    type: 'POST',
    dataType: "json",
    data: dataToSend
    success: function (response) {
        
    }
})

Back-end:

if request.method == 'POST':

   print(request.args())
   print(request.args.getlist([0]))
Puzzlemaster
  • 143
  • 11

1 Answers1

1

You may need to send contentType to 'application/json' in the ajax and stringify the json. See here for proper formatted request: jQuery posting valid json in request body

If the POST is valid JSON, then it is auto-decoded by flask.

if request.method == 'POST':
    print(request.json)
    for item in request.json:
       #do something with the item.