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]))

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.