Home > Web Front-end > JS Tutorial > Solve the problem of AjaxSubmit uploading files prompt to download files under IE

Solve the problem of AjaxSubmit uploading files prompt to download files under IE

韦小宝
Release: 2018-01-01 19:41:17
Original
2287 people have browsed it

This article mainly introduces how to solve the problem of AjaxSubmit uploading files under IE and prompting to download files. Friends who are interested in ajax can refer to the article about solving the problem of AjaxSubmit uploading files under IE and prompting to download 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) { 
  //获取登录人员的id 
  Integer userId = (Integer) session.getAttribute(BaseConstant.SESSION_UERID_KEY); 
  JSONObject json = new JSONObject(); 
  if (request instanceof MultipartHttpServletRequest) { 
    //获取上传文件的文件名 
      String fileName = file.getOriginalFilename(); 
      String subfix = FileUtils.getFileExtend(fileName); 
    } 
return ""; 
  }
Copy after login


js:End


$('#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  
    }; 
    //提交表单 
    $(this).ajaxSubmit(optionss); 
    // !!! Important !!! 
    // 为了防止普通浏览器进行表单提交和产生页面导航(防止页面刷新?)返回false 
    return false; 
  });<pre name="code" class="javascript">function showResponse(data) { 
  data = JSON.parse(data.responseText); 
  if(data.type != null) { 
  } 
}
Copy after login


If the returned type is json, this problem only occurs in IE, but is normal in Chrome and Firefox. To solve the problem, only text/html can be returned.
The type returned by the backend cannot be json, but text/html, and then convert the returned type to json type.

The above is what the editor introduces to you to solve the problem of AjaxSubmit uploading files under IE and prompting to download files. I hope it will be helpful to everyone! !

Related recommendations:

How Ajax implements website hijacking detection

Detailed examples of kkpager to implement ajax paging query function

Ajax implementation of dynamic loading of combo box examples

The above is the detailed content of Solve the problem of AjaxSubmit uploading files prompt to download files under IE. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template