最近在弄一个上传的小功能,需要往后台传递一些动态参数,网上有一些传参数可能是因为版本不对也没成功。仔细看了官网的一些说明,搞定了。
3.2中传递参数用的的是'formData':{'somekey':'somevalue'}这个属性,但其不能传递动态参数;动态传参需要用到settings这个方法,官网上也说明了。示例如下:
jQuery(document).ready(function () {
var ctrlid = getQueryString("ctrlptid");
jQuery("#file_upload").uploadify({
'buttonImage': '/uploadify/browse-btn.png',
'auto': false,
'successTimeout': 99999,
'swf': '/uploadify/uploadify.swf',
'queueID': 'uploadfileQueue',
'uploader': '/uploadify/UploadHandler.ashx',
'fileSizeLimit': '0',
'fileTypeExts': '*.gif; *.jpeg; *.jpg; *.png',
'multi': false,
'queueSizeLimit': 5,
'progressData': 'speed',
'overrideEvents': ['onDialogClose'],
//'formData': { 'someKey': 'someValue', 'ctrlid': 2 },//这里只能传静态参数
//'fileTypeExts': '*.rar;*.zip;*.7z;*.jpg;*.jpge;*.gif;*.png',
'onSelectError': function (file, errorCode, errorMsg) {
switch (errorCode) {
case -100:
alert("上传的文件数量已经超出系统限制的" + jQuery('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件!");
break;
case -110:
alert("文件 [" + file.name + "] 大小超出系统限制的" + jQuery('#file_upload').uploadify('settings', 'fileSizeLimit') + "大小!");
break;
case -120:
alert("文件 [" + file.name + "] 大小异常!");
break;
case -130:
alert("文件 [" + file.name + "] 类型不正确!");
break;
}
},
'onClearQueue': function (queueItemCount) {
alert("取消上传");
return;
},
'onQueueComplete': function (queueData) {
alert("文件上传成功!");
return;
},
'onUploadStart': function (file) { $("#file_upload").uploadify("settings", "formData", { 'ctrlid': ctrlid });
//在onUploadStart事件中,也就是上传之前,把参数写好传递到后台。
}
});
});
后台取得参数的话,可以用context.Request.Form["ctrlid"] 来取得。