jquery 如何动态绑定传递到后台上传组件参数

 $("#upload_photo").uploadify({
	         'auto' : false,
	            'method' : "post",
	            'height' : 20,
	            'width' : 100,
	            'swf' : '<%=basePath%>js/uploadify.swf',
	            'uploader' : '<%=basePath%>attach/api/upload',
	          'fileTypeDesc' : '格式:txt,xls,xlsx,doc,docx,rar,zip,jpg,png,pdf',     //描写叙述
	            'fileTypeExts' : '*.txt;*.xls;*.xlsx;*.doc;*.docx;*.rar;*.zip;*.jpg;*.png;*.pdf',         //文件类型
	            'fileSizeLimit' : '30000KB',          //文件大小
	            'buttonText' : '选择文件',         //按钮名称
	            'fileObjName' :'uploadify',
	            'multi' :true,
	            'successTimeout' : 5,
	            'requeueErrors' : false,
	            'removeTimeout' : 1,
	            'removeCompleted' : true,
	            'onSelectError' : function(file,errorCode,errorMsg) {
	            alert("失败");
	                  if(errorCode==-110){
	                      this.queueData.errorMsg = "文件太大。无法上传。";
	                  }
	             },
	             '<span style="color:#ff0000;background-color: rgb(255, 255, 255);"><strong>onUploadStart':function(file){//动态绑定參数向后台传送
	            	 var groupName=$(".select2").val();
	            	 $('#upload_photo').uploadify('settings','formData',{'groupName':groupName});
	             },</strong></span>
	             'onUploadSuccess' : function(file, data, response){
	              var attachs = jQuery.parseJSON(data);
	              var attach=attachs.result[0];
	              // alert(attach2);       
	                 if(attach.id!=null)
	                 $("#tbfj tbody").append("<tr name=\""+attach.id+"\"><td>"+attach.fileName+"</td><td>"+attach.fileSize+"</td><td>"+attach.uploadDate+"</td><td><a href=\"${pageContext.request.contextPath}/attach/api/download/"+attach.id+"\">下载</a></td><td><a class=\"del\">删除</a></td></tr>");

	         },
	           
	     });

动态传递參数须要通过红色部分实现:

1、首先加入onUploadStart函数,在上传開始时设置參数

2、通过$('#upload_photo').uploadify('settings','formData',{'groupName':groupName});设置參数

    说明:settings:操纵名称,代表对上传进行设置

                formData:不能改,表示将向表单数据中加入參数

               {'groupName':groupName}:传递给背景参数。{key:value,.....}

版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-10-23 17:46  zfyouxi  阅读(221)  评论(0编辑  收藏  举报