我迷失在这里。我正在尝试设置一个简单的文件上传,由SWFUpload处理。文件选择后没有任何反应。我没有看到发送请求,并且我的控制台中没有任何内容。 swf对象应该立即调用我的upload_url页面吗?
var swfu,jobForm;
var j = jQuery.noConflict();
j(window).load(function() {
jobForm = j('.admin-atomic-form form');
swfu = new SWFUpload({
upload_url : "URL/upload.php",
flash_url : "URL/swfupload.swf",
file_size_limit : "20 MB",
file_types : "*.doc;*.pdf;*.rtf;*docx;*.jpg;",
//file_types_description : "All Files",
file_upload_limit : "1",
button_placeholder_id : "swfuploader",
button_image_url : "URL/file-browse.png",
button_width: 100,
button_height: 30,
upload_start_handler : uploadStart,
upload_success_handler : uploadSuccess
});
//jobForm.form.submit(function(ev){ev.preventDefault()})
});
function uploadStart(){
//.submit()
console.log(this,'start');
};
function uploadSuccess(){
//form.submit()
console.log('success');
}
答案 0 :(得分:0)
开始上传文件的过程分为两个步骤:1。选择一个文件(然后在输入框中填充路径),2。您必须提交表单才能开始实际上传。
我假设您没有执行第2步,因为在您的代码中,您已注释掉form.submit()
请取消注释此行://jobForm.form.submit(function(ev){ev.preventDefault()})
然后在选择文件后,提交表单。
答案 1 :(得分:0)
SWFUploadObj.startUpload();
需要被触发,这就是对指定的upload_url发起POST请求的原因。如果某个默认设置触发了这个方法,那肯定不适合我。
以下是我的一些功能示例:
// Bound to file_queued_handler : sets a flag that there is a file waiting to upload
function swfuFileQueued(file){
resumeQueued = true;
$j('#browseFile').val(file.name);
}
//Bound to form submit event:
//a successful upload will submit this form again once the success response with the server-moved and renamed filename comes back from the file upload handling script
function swfuFormSubmit(ev){
if(uploadSuccess){
return true;
} else {
if(resumeQueued == true){
ev.preventDefault();
swfuUploadStart(); // see next function
} else {
return true;
}
}
}
function swfuUploadStart(){
try {
swfu.startUpload(); // <-- The actual method that begins the file upload request
} catch (e) {
}
return false;
}
function swfuProgress(){ ...
function swfuError(){ ...
function swfuSuccess(){
//update input element containing filename or id to send with form
//update a status box with "Success"
//uploadSuccess = true
//form.submit() once more, this time uploadSuccess will tell the function to continue on and actually submit itself
了解SWFUpload过程的有用URL:http://www.dconstructing.com/2010/07/08/making-swfupload-work