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";
}
此处为防止遗忘的个人总结,参考了其他朋友的文章,链接如下: