解决IE下AjaxSubmit上传文件提示下载文件问题
程序员文章站
2022-03-04 17:06:45
springmvc后端:
@requestmapping(value="scorefileupload",produces = "text/html; chars...
springmvc后端:
@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 ""; }
js:端
$('#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) { } }
如果返回的类型是json,这种问题只在ie下出现过,chrome和firefox则正常。为了解决问题,只能返回text/html。
后端返回的类型不能是json,而是text/html,然后把返回的类型转换为json类型。
以上所述是小编给大家介绍的解决ie下ajaxsubmit上传文件提示下载文件问题,希望对大家有所帮助