<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="./jquery-3.3.1.min.js"></script> </head> <body> <div class="modal-body"> <!--multiple="multiple" 表示可以选多个文件--> <input type="file" id="file" onchange="uploadFile(this)"> </div> <script> function uploadFile(source) { var file=$(source); console.log("file",file) var tmp=file[0].files[0]; console.log("tmp",tmp) if(tmp){ var formdata = new FormData(); formdata.append("file",tmp); console.log("formdata",formdata); $.ajax({ url: "http://39.96.12.37:8001/ossService/fileupload", type: "post", data:formdata, dataType: "json", processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false, // 告诉jQuery不要去设置Content-Type请求头 success: function (res) { console.log("res",res) } }) } } </script> </body> </html>