JQuery ajaxFileUpload plugin Asynchronous upload file is very simple.
Step 1: you need to download the jQuery ajaxFileUpload file in GitHub.
The github download address:
https://github.com/carlcarl/AjaxFileUpload
The ajaxFileUpload.js file is introduced in the header file, and the code is as follows:
- <script type="text/javascript" src="${ctx}/asset/lib/ajaxfileupload.js"></script>
Step 2: Using jQuery ajaxFileUpload in the web page,we need to use onchange event, and define a ID, HTML code is as follows:
- <input type='file' name='files' id="fileUpload" onchange="uploadExcelFile();"/>
Then we implement Ajax file upload in the <script></script> tag, and the "fileElementId" attribute points to the ID defined in the input tag.
- function uploadExcelFile() {
- $.ajaxFileUpload({
- url:"./questionType/importExcel",
- type:"POST",
- fileElementId :"fileUpload",
- success:function (data) {
- //do something
- },
- error:function(erro){
- //do something
- }
- });
- }
Step 3: Uploading files with springmvc's MultipartFile class in the Java background.
- @PostMapping("/questionType/importExcel")
- @ResponseBody
- public String uploadExportWord(MultipartFile files) {
- System.out.println("============"+file.getOriginalFilename());
- //do something
- return null;
- }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.