ajaxfileupload的兼容IE9、IE10和中文乱码问题

要让ajaxfileupload兼容IE9、IE10,修改它的源码

找到以下代码

if(window.ActiveXObject) {
    var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
     if(typeof uri== 'boolean'){
         io.src = 'javascript:false';<pre name="code" class="javascript">ajaxFileUpload: function(s) {
        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout		
        s = jQuery.extend({}, jQuery.ajaxSettings, s);
        var id = new Date().getTime()        
	var form = jQuery.createUploadForm(id, s.fileElementId);<pre code_snippet_id="1584425" snippet_file_name="blog_20160222_2_1150741" name="code" class="javascript">io.src = uri; } }
 

 替换为 

if(window.ActiveXObject) {
   if(jQuery.browser.version=="9.0" || jQuery.browser.version=="10.0"){
    	var io = document.createElement('iframe');
    	io.id = frameId;
    	io.name = frameId;
    }else if(jQuery.browser.version=="6.0" || jQuery.browser.version=="7.0" || jQuery.browser.version=="8.0"){
    	var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
    	if(typeof uri== 'boolean'){
    	    io.src = 'javascript:false';
    	}
    	else if(typeof uri== 'string'){
    	    io.src = uri;
    	}
    }
}

如果只是做这样的修改,在IE下还是会有各种问题,你应该这样配置

前台

 $.ajaxFileUpload  
           ({  
               url:'',
               secureuri:false,  
               fileElementId:'exclFile',  
               dataType: 'text',  
               success: function (data, status)  
               {  	
            	   data=JSON.parse(data);
secureuri:false解决iframe的跨域问题,dataType使用text而不是json是因为在springmvc下的中文乱码问题,需要JSON.parse(data)将json串解析为对象
java后台

public void importBuyerByExcel(@RequestParam() MultipartFile exclFile,HttpSession session,HttpServletRequest request,ModelMap map,HttpServletResponse response) 
       throws IOException{
     <span style="white-space:pre">	</span>response.setContentType("text/html");
    <span style="white-space:pre">	</span>response.getWriter().write(JSONObject.fromObject(map).toString()); 
     }   
后台用response返回json串的原因是中文乱码,搞了好久都没解决,无奈之下只有这样搞了

让ajaxfileupload支持多个参数上传,找到以下代码

ajaxFileUpload: function(s) {
        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout		
        s = jQuery.extend({}, jQuery.ajaxSettings, s);
        var id = new Date().getTime()        
	var form = jQuery.createUploadForm(id, s.fileElementId);
替换为

ajaxFileUpload: function(s) {
        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout		
        s = jQuery.extend({}, jQuery.ajaxSettings, s);
        var id = new Date().getTime()        
	var form = jQuery.createUploadForm(id, s.fileElementId, s.tag_name, s.tag_link, s.tag_sort, s.tag_status, s.tag_id);





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值