我已经看到其他人如何捕获从他们的上传器后端返回的数据。 (参见:How do i get swfupload to return image URL after upload?)但是我一直在.bind()上遇到javascript错误。有什么想法吗?
代码:
upload1 = new SWFUpload({
// Backend Settings
upload_url: "uploader2.py",
post_params: various params,
// File Upload Settings <a id="printimages" style="float: right">Print Images</a>
file_size_limit : "100 MB", // 100MB
file_types : "",
file_types_description : "Any File",
file_upload_limit : 1000,
file_queue_limit : 0,
// Event Handler Settings (all my handlers are in the Handler.js file)
swfupload_preload_handler : preLoad,
swfupload_load_failed_handler : loadFailed,
file_dialog_start_handler : fileDialogStart,
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
// Button Settings
button_image_url : "images/XPButtonUploadText_61x22.png",
button_placeholder_id : "ButtonPlaceholder1",
//button_placeholder : "spanButtonPlaceholder1",
button_width: 61,
button_height: 22,
moving_average_history_size: 1,
// Flash Settings
flash_url : "swf/swfupload.swf",
flash9_url : "swf/swfupload_fp9.swf",
// My settings
custom_settings : {
progressTarget : "fsUploadProgress1",
cancelButtonId : "btnCancel1",
tdFilesQueued : document.getElementById("tdFilesQueued"),
tdFilesUploaded : document.getElementById("tdFilesUploaded"),
tdErrors : document.getElementById("tdErrors"),
tdCurrentSpeed : document.getElementById("tdCurrentSpeed"),
tdCurrentFile : document.getElementById("tdCurrentFile"),
tdAverageSpeed : document.getElementById("tdAverageSpeed"),
tdMovingAverageSpeed : document.getElementById("tdMovingAverageSpeed"),
tdTimeRemaining : document.getElementById("tdTimeRemaining"),
tdTimeElapsed : document.getElementById("tdTimeElapsed"),
tdPercentUploaded : document.getElementById("tdPercentUploaded"),
tdSizeUploaded : document.getElementById("tdSizeUploaded"),
tdProgressEventCount : document.getElementById("tdProgressEventCount")
},
// Debug Settings
debug: false
}).bind('uploadSuccess', function(event, file, serverData){
alert(serverData);
});
答案 0 :(得分:2)
链接的示例使用swfupload jquery plugin并且它具有绑定功能。你的例子是在没有jquery的情况下使用插件,所以当你在新的SWFUpload对象上调用bind时,你得到一个错误,因为它没有绑定方法。使其工作的最简单方法是实现您的回调函数。
// Backend Settings
upload1= new SWFUpload({
upload_url: "uploader2.py",
post_params: various params,
// File Upload Settings <a id="printimages" style="float: right">Print Images</a>
file_size_limit : "100 MB", // 100MB
file_types : "",
file_types_description : "Any File",
file_upload_limit : 1000,
file_queue_limit : 0,
// Event Handler Settings (all my handlers are in the Handler.js file)
swfupload_preload_handler : preLoad,
swfupload_load_failed_handler : loadFailed,
file_dialog_start_handler : fileDialogStart,
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : myUploadSuccessHandler,
upload_complete_handler : uploadComplete,
// Button Settings
button_image_url : "images/XPButtonUploadText_61x22.png",
button_placeholder_id : "ButtonPlaceholder1",
//button_placeholder : "spanButtonPlaceholder1",
button_width: 61,
button_height: 22,
moving_average_history_size: 1,
// Flash Settings
flash_url : "swf/swfupload.swf",
flash9_url : "swf/swfupload_fp9.swf",
},
// Debug Settings
debug: true
});
// your callback
function myUploadSuccessHandler (file, serverData){
alert(file, serverData);
}
另一个有用的事情是将debug选项变为true:)