Solve the problem that AjaxSubmit prompts downloading files when uploading files under IE. ajaxsubmit uploads files
Springmvc backend:
@ RequestMapping (value = "scoreFileUpload", produces = "text/html; charset = UTF-8") @ ResponseBody public String upload (HttpSession session, @ RequestParam ("file1") MultipartFile file, @ RequestParam ("paperId") String paperId, HttpServletRequest request) {// obtain the id of the logon user Integer userId = (Integer) session. getAttribute (BaseConstant. SESSION_UERID_KEY); JSONObject json = new JSONObject (); if (request instanceof MultipartHttpServletRequest) {// get the file name of the uploaded file String fileName = file. getOriginalFilename (); String subfix = FileUtils. getFileExtend (fileName);} return "";}
Js: Terminal
$ ('# FileForm '). submit (function () {var _ businessDetailId = $ ("# businessDetailId "). val (); var _ paperId = $ ("# paperId "). val (); var url = "scoreFileUpload? PaperId = "+ _ paperId +" & businessDetailId = "+ _ businessDetailId; var optionss = {dataType:" text/html ", type: 'post', url: url, // beforeSubmit: showRequest, complete: showResponse, clearForm: false, timeout: 3000000}; // submit the form $ (this ). ajaxSubmit (optionss );//!!! Important !!! // To prevent normal browsers from submitting forms and generating page navigation (to prevent page refreshing ?) Return false;}); <pre name = "code" class = "javascript"> function showResponse (data) {data = JSON. parse (data. responseText); if (data. type! = Null ){}}
If the returned type is json, this problem occurs only in ie, and chrome and firefox are normal. To solve the problem, only text/html is returned.
The type returned by the backend cannot be json, but text/html. Then, the returned type is converted to json.
The above section describes how to solve the problem that AjaxSubmit prompts you to download files under IE. I hope it will help you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!