spring mvc中ajaxfileupload多文件上传

jquery版本为1.7.2,在使用时不要引用ajaxfileupload的jquery,直接使用1.7.2的,不然会有问题。
在ajaxfileupload.js文件中找到createUploadForm: function(id, fileElementId, data)函数,在函数中有如下代码
var oldElement = jQuery('#' + fileElementId);
var newElement = jQuery(oldElement).clone();
jQuery(oldElement).attr('id', fileId);
jQuery(oldElement).before(newElement);
jQuery(oldElement).appendTo(form);
将该段代码修改如下
for(var index = 0; index < fileElementId.length; index++){
	var oldElement = jQuery('#' + fileElementId[index]);
	var newElement = jQuery(oldElement).clone();
	jQuery(oldElement).attr('id', fileId);
	jQuery(oldElement).before(newElement);
	jQuery(oldElement).appendTo(form);
}


修改完成后保存。
html在页面中代码如下
var tmp=[];
for(var index = 0; index < document.getElementById_x_x_x("upload").elements.length; index++){
tmp.push(document.getElementById_x_x_x("upload").elements[index].id);
}
 $.ajaxFileUpload({  
     url:'自己的url',       
     secureuri:false,  
     fileElementId:tmp,                          
     dataType: 'json',          
     success:function (data, status)  //服务器成功响应处理函数
    {
  alert("suces");
    },
    error: function (data, status, e)//服务器响应失败处理函数
     {
            alert("error");
             alert(e);
       }
}); 
<form id="upload" name="upload" enctype="multipart/form-data" >
	<input id="file1" name="filename" type="file"></input><br>
	<input id="file2" name="filename" type="file"></input>
</form>

controller中代码如下:
@ResponseBody
public String uploadFile( @RequestParam("fileName") MultipartFile[] clientFiles,HttpServletRequest req){
//具体处理
return "success";
}


此处为防止遗忘的个人总结,参考了其他朋友的文章,链接如下:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值