ajax single-file upload and file upload

Reference links:

1. https://www.imooc.com/article/69973 (Ajax simple method to achieve a variety of asynchronous file upload)

2. https://www.cnblogs.com/hesijian/p/9199231.html (distal portion)

3. https://blog.csdn.net/qq_36489998/article/details/82779601 (ajax dynamic upload multiple files)

4. https://blog.csdn.net/technologys/article/details/81674188 (back and front end)

5. https://www.imooc.com/article/69973 (Ajax simple method to achieve a variety of asynchronous file upload)

 Description:

 By means of a front end portion FormData objects, h5 FormData a newly introduced class, the form data can be simulated;

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>文件上传</title>
</head>
<body>
<form id= "uploadForm"> 
      <p >指定文件名: <input type="text" name="filename" value= ""/></p > 
      <p >上传文件: <input type="file" name="file1" id="file1"  multiple="multiple"  /></p>
      <p >上传文件: <input type="file" name="file2" id="file2" /></p>
      <p >上传文件: <input type="file" name="file3" id="file3" /></p> 
      <input type="button" value="上传" onclick="doUpload()" /> 
</form> 
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="js/common.js"></script>   
<script type="text/javascript">
//获取token
var token = parent.window.document.getElementById("token").value;   
     
function doUpload() { 
    var formData = new FormData();
    formData.append("token", token);
    formData.append("file1", $('#file1')[0].files[0]);
    formData.append("file2", $('#file2')[0].files[0]);
    formData.append("file3", $('#file3')[0].files[0]);
    $.ajax({ 
         url: 'bookController/uploadMult' , 
         type: 'post', 
         data: formData, 
         cache: false,
         processData: false,
         contentType: false,
         async: false
    }).done(function(res) {
         
    }).fail(function(res) {
         
    });
}
 
 
</script> 
</body>
</html>

Background means MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; implemented

Published 100 original articles · won praise 47 · views 210 000 +

Guess you like

Origin blog.csdn.net/sl1990129/article/details/102856957