https://www.cnblogs.com/lidgblogs/archive/2017/09/01/7403828.html
ajax模仿form上传:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <form id= "uploadForm"> <p>指定文件名: <input id="reportType" type="text" name="filename" value= "1"/></p > <p>上传文件: <input type="file" name="file" value=""/></p> <input type="button" value="上传" οnclick="doUpload()" /> </form> <script src="jquery-1.8.3.min.js"></script> <script> function doUpload() { var formData = new FormData($("#uploadForm")[0]); var reportType = $('#reportType').val(); $.ajax({ url: 'http://192.168.1.124/creditReoprtImport/import' , type: 'POST', data: {reportType:reportType,formData:formData}, async: false, cache: false, contentType: false, processData: false, success: function (returndata) { alert(returndata); }, error: function (returndata) { alert(returndata); } }); } </script> </body> </html>