ajaxFileUpload 多文件上传

前端之家收集整理的这篇文章主要介绍了ajaxFileUpload 多文件上传前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前提条件:

ajaxFileUpload.js插件文件上传

步骤:

1、修改源码,(源码只支持单个文件上传):

  1. //修改代码-------
  2. //var oldElement = jQuery('#' + fileElementId);
  3. //var newElement = jQuery(oldElement).clone();
  4. //jQuery(oldElement).attr('id',fileId);
  5. //jQuery(oldElement).before(newElement);
  6. //jQuery(oldElement).appendTo(form);
  7. //修改代码-------
  8. //修改代码-------
  9. for(var i in fileElementId){
  10. var oldElement = jQuery('#' + fileElementId[i]);
  11. var newElement = jQuery(oldElement).clone();
  12. jQuery(oldElement).attr('id',fileId);
  13. jQuery(oldElement).before(newElement);
  14. jQuery(oldElement).appendTo(form);
  15. }
  16. //修改代码-------

2、使用方法
  1. $.ajaxFileUpload({
  2. url : "./upload/upload.action",secureuri : false,//fileElementId:'uploadfile1',//原使用方法
  3. fileElementId : ['uploadfile1','uploadfile2','uploadfile3','uploadfile4','uploadfile5'],//现使用方法
  4. dataType : 'json',success : function(data) {
  5. ajaxLoadEnd();
  6. if (data.result == "success") {
  7. $.messager.alert('信息','导入成功。','info');
  8. } else {
  9. $('#import_right').dialog('open');
  10. $.messager.alert('信息','导入失败。<br>错误信息:'+data.message,'error');
  11. }
  12. },error : function(data,status,e)
  13. {
  14. ajaxLoadEnd();
  15. $.messager.alert('信息','导入失败。<br>错误信息:网络异常或表单数据错误。','error');
  16. }
  17. });

猜你在找的Ajax相关文章