AjaxFileUpload实现多文件上传
来源:互联网 发布:邪恶镰刀 数据 编辑:程序博客网 时间:2024/05/23 20:30
去年5月中旬在项目中使用过Ajax上传文件(一直都在飘,也就最近两周开始写博客了),现在要使用的时候不得不再去看过去的代码了,我是将原本的 AjaxFileUpload 单文件改成了多文件上传的,虽然不是太灵活但也能满足需求了。
使用的是 AjaxFileUpload v2.1,地址 http://www.phpletter.com/Our-Projects/AjaxFileUpload/
完成多文件上传需要改动 ajaxfileupload.js 文件,将原始的代码注释掉再改写,大约在 39行
/* var oldElement = jQuery('#' + fileElementId);var newElement = jQuery(oldElement).clone();jQuery(oldElement).attr('id', fileId);jQuery(oldElement).before(newElement);jQuery(oldElement).appendTo(form); */if(typeof(fileElementId) == 'string'){ fileElementId = [fileElementId]; }for(var i in fileElementId){ var oldElement = jQuery('#' + fileElementId[i]); var newElement = jQuery(oldElement).clone(); jQuery(oldElement).attr('id', fileId + i); jQuery(oldElement).before(newElement); jQuery(oldElement).appendTo(form); }
更改了之后,在上传参数 fileElementId 更改为数组,其余的参照官方文档
$.ajaxFileUpload({url: 'test.php',secureuri:false,//加入到数组中fileElementId:['fileone','filetwo'],dataType: 'json',data:{'width': $('#width').val(),'height': $('#height').val(),'fileone': $('#fileone').val(),'filetwo': $('#filetwo').val(),'content': $('#content').val()},success: function (data, status){if(typeof(data.error) != 'undefined'){if(data.error != ''){//返回的错误信息}else{//成功返回}}},error: function (data, status, e){//错误处理alert(e+'|date:'+data+', status:'+status);}});
间隔时间比较久,而现在需要的只是单文件上传,所以未知是否有疏漏之处。
2015-02-05 编辑
发现了有人发布了灵活的多文件上传,贴过来 http://blog.csdn.net/itmyhome1990/article/details/36433621
0 0
- AjaxFileUpload实现多文件上传
- AjaxFileUpload实现文件上传
- ajaxFileUpload+struts2实现多文件上传
- AjaxFileupload.js实现多文件上传
- struts2+ajaxfileupload.js实现多文件上传
- ajaxfileupload 多文件上传
- ajaxFileupload多文件上传
- ajaxFileUpload 多文件上传
- ajaxFileupload多文件上传
- ajaxfileupload多文件上传
- ajaxFileupload多文件上传
- ajaxFileupload多文件上传
- ajaxFileUpload多文件上传
- AjaxFileUpload实现文件异步上传
- ajaxfileupload实现文件异步上传
- 使用ajaxFileUpload实现文件上传
- ajaxFileUpload实现异步文件上传
- springmvc + ajaxFileUpload多文件上传
- Error creating bean with name 'xx': Injection of autowired dependencies failed
- HDOJ 3232 Crossing Rivers 简单概率
- poj 1694 树形贪心
- tomcat显示目录文件列表
- jQuery 引用地址{包括jquery和google提供的地址}, 节省你不必要的流量
- AjaxFileUpload实现多文件上传
- Javascript---有趣的一段代码--this指向问题
- windows下捕获dump
- Android-谷歌账号解锁
- Oracle的锁表与解锁
- MongoDB架构篇-Replica Set 副本集
- Spring AOP三种拦截方式举例详解
- Codeforces 158B
- 全选和全不选