我正在尝试向swfupload动态添加一些帖子参数。但是当脚本执行并且文件上传时,POST参数会丢失。任何信息我可能做错了什么? 我的代码如下:
var swfu = new SWFUpload({
upload_url : "http://something/location",
flash_url : "http://an-absolute-url-to/swfupload.swf",
file_post_name : "fileObject",
http_success : [201, 202],
assume_success_timeout : 0,
file_types : "*.jpg;*.gif;*.png",
file_types_description: "Web Image Files",
file_size_limit : "1000 MB",
file_upload_limit : 10,
file_queue_limit : 2,
debug : true,
prevent_swf_caching : false,
button_placeholder_id : "button",
button_width : 61,
button_height : 22,
button_text : "<b>Click</b> <span class=\"redText\">here</span>",
button_text_style : ".redText { color: #FF0000; }",
button_text_left_padding : 3,
button_text_top_padding : 2,
button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES,
button_disabled : false,
button_cursor : SWFUpload.CURSOR.HAND,
button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
file_queue_error_handler : function(e){window.alert("ERror@")},
upload_start_handler : function(e){
$.ajax({url:"/auth",
data:"file=" + e.name,
success: function(msg){
$.swfu.addPostParam("param1",msg.p1);
$.swfu.addPostParam("param2",msg.p2);
}
});
},
答案 0 :(得分:0)
通过将file_dialog_complete_handler的事件处理程序添加到SWFUpload构造中,我将我连接到文件对话框完成中:
file_dialog_complete_handler : fileDialogComplete,
然后我按如下方式实现了javascript函数fileDialogComplete(我有2个表单字段,类别和注释,并使用jquery获取它们):
function fileDialogComplete(msg) {
swfu.addPostParam( "category", $('#category').val());
swfu.addPostParam( "notes", $('#notes').val());
swfu.startUpload();
}
现在,当选择文件时,它会启动fileDialogComplete方法,该方法将启动上传。然后在服务器端,您可以看到我的帖子变量:
Post[Filename]=Finland.png
Post[category]=2
Post[notes]=Here we go
Post[Upload]=Submit Query