使用Flask 1.0.2on Windows,Python 3.6 64bit
首先我通过jquery ajax调用发送数据,这在 JS 端是有效的json
var myData = '{ "id": "' +clickedID +'" }'
$.ajax({
type: "POST", // HTTP method POST or GET
contentType: 'application/json; charset=utf-8', //content type
url: $SCRIPT_ROOT + '/colors/delete', //Where to make Ajax calls
dataType:'json', // Data type, HTML, json etc.
processData: false,
data:JSON.stringify(myData),
});
Run Code Online (Sandbox Code Playgroud)
在烧瓶中,我捕获了 POST 请求并尝试解析它:
if request.method == "POST":
print("got request method POST")
if request.is_json:
print("is json")
data_json = request.get_json(force=True)
data_req = request.data …Run Code Online (Sandbox Code Playgroud)