HTML代码
<form id="form" enctype="multipart/form-data" method="post" >
<input type="file" name="file1" id="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"><br>
<input type="text" name="l1" id="" value="1"><br>
<input type="number" name="l2" id="" value="2"><br>
<input type="checkbox" name="l3" id="" ><br>
<input type="submit" value="上传数据">
</form>
jquery代码
$("#form").submit(function (e) {
e.preventDefault();
var formData = new FormData($("#form")[0]);
$.ajax({
url:"http://0.0.0.1/api",
type:'post',
data: formData,
contentType: false,
processData: false,
success:function(res){
console.log(res);
},
error:function(error){
console.log(error);
}
})
});
后端Flask数据处理
@app.route('/api',methods=['GET','POST'])
def api():
d1 = request.form.get("l1")
d2 = request.form.get("l2")
d3 = request.form.get("l3")
file = request.files.get('file')
print(file)
dict = {"code":200,"data":"处理完毕"}
return jsonify(dict)