0
我的AJAX調用看起來是這樣的:如何在Python中接收對象數組作爲參數使用AJAX作爲HTTP請求傳遞Flask?
$.ajax({
url: "/doSomeCoolThingOnServer",
type: "POST",
async: false,
data: {
simple_string: "Variable sent from client side",
array_of_strings: ["John", "George"],
array_of_objects: [
{ city: "Shanghai", population: 1000 },
{ city: "Budapest", population: 2501 }
]
},
success: function(response) {
console.log("===== SUCCESS =====");
console.log(response);
},
error: function(response) {
console.log("===== ERROR =====");
console.log(response);
}
});
我想收到數組對象如Python的類型的字典的數組的,但我有空數組返回。
@app.route("/doSomeCoolThingOnServer", methods=['POST'])
def doSomeCoolThingOnServer():
simple_string = request.form['simple_string']
array_of_strings = request.form.getlist('array_of_strings[]')
array_of_objects = request.form.getlist('array_of_objects[]')
print(simple_string) #returns desired string
print(array_of_strings) # returns desired array
print(array_of_objects) # returns empty array
請指教如何在Python中接收對象數組作爲參數Flask作爲HTTP POST請求使用AJAX傳遞?