我想使用Uploadify jQuery插件在ASP.net上传文件。但是当用户选择一个文件并点击“上传”按钮时按钮我想向服务器发送一些额外的参数。我写了这段代码:
<a id="bb" href="#">Start Upload</a>
| <a href="javascript:$('#<%=fuBrandIcon.ClientID%>').fileUploadClearQueue()">Clear</a>
<table width="50%">
<tr>
<td>BrandName</td>
<td>
<input id="BrandName" type="text" />
</td>
</tr>
<tr>
<td>BrandAbbr</td>
<td>
<input id="txtBrandAbbr" type="text" />
</td>
</tr>
<tr>
<td>
Icon
</td>
<td>
<asp:FileUpload ID="fuBrandIcon" runat="server" ClientIDMode="Static" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
</td>
</tr>
</table>
<script type = "text/javascript">
$(window).load(
function () {
alert($("#BrandName").val());
$("#fuBrandIcon").fileUpload({
'uploader': '../UplodyFile/uploader.swf',
'cancelImg': '../UplodyFile/cancel.png',
'buttonText': 'Browse Files',
'script': 'PublicHandler.ashx',
'folder': 'uploads',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'multi': false,
'auto': false,
'onUploadStart' : function(file) {
alert('Starting to upload ' + file.name);
}
// "scriptData": { 'BrandName': $("#BrandName").val(), "BrandAbbr": $("#txtBrandAbbr").val(), "ActionPage": "Brand", "Action": "Add" }
});
$("#bb").click(function() {
$('#<%=fuBrandIcon.ClientID%>').fileUploadStart();
});
});
</script>
当用户点击BrandName
链接时,我想将用户选择的文件以及BrandAbbr
和bb
发送到服务器。但是此代码会发送空的BrandName
和BrandAbbr
值。
编辑:我编写此代码,但我在undifine
<script>
$(function () {
$("#file_upload").uploadify({
height: 30,
swf: '../img/uploadify.swf',
uploader: 'Handler.ashx',
width: 120,
auto: false
});
$('#file_upload').uploadifySettings('name', $("#Text1").val());
});
</script>
请帮帮我。感谢
答案 0 :(得分:1)
您可以通过formData
发送其他数据。 return to the Documentation
<强>更新强> 无论如何,文档中呈现的方式对我来说效果不佳。我使用了这段代码并且它正在工作
$('#uploadify_1').uploadifySettings('property_something', 'value_something');