[原创]SWFUpload能上传视频不能提交表单的问题解决办法

最近在做模板时候发现,原来能用的swfupload上传视频的功能,现在不能用了?!但是视频文件上传完成后不能提交表单信息,总是提示:“Error submit form”

开始以为是代码调用的问题,去除了不必要的js代码,问题依然存在!swfupload上传的流程可以通过调用代码分析出来,代码如下:
……..

upload_progress_handler: uploadProgress, //上传进度显示处理函数uploadProgress
upload_error_handler: uploadError,//上传错误处理函数uploadError
upload_success_handler: uploadSuccess,//上传成功处理函数uploadSuccess
upload_complete_handler: uploadComplete,//上传完成处理函数uploadComplete 问题应该就出在这个函数中
………..

于是打开handler.js中查看uploadComplete的代码如下:

function uploadComplete(file) {
try {
if (this.customSettings.upload_successful) {

this.setButtonDisabled(true);
uploadDone(); //这个就是完成上传文件后的处理函数了
} else {
file.id = “singlefile”;
var progress = new FileProgress(file, this.customSettings.progress_target);
progress.setError();
progress.setStatus(“File rejected”);
progress.toggleCancel(false);

var txtFileName = document.getElementById(“txtFileName”);
txtFileName.value = “”;
//validateForm();

alert(“There was a problem with the upload.\nThe server did not accept it.”);
}
} catch (e) {
}
}

继续查看uploadDone()函数的代码,代码如下:

// Called by the queue complete handler to submit the form
function uploadDone() {
try {

document.forms[1].submit();//罪魁祸首在此

居然遍历取当前页面的forms的第二个进行提交,不管是不是要提交的表单都提交

没有找到时候就提示:Error submitting form

}

catch (ex) {
alert(“Error submitting form”);
}
}

问题找到了于是准备进行如下修改:

1.swfupload引用时的customSettings设置上传文件完成后要提交的form的Id:upload_form

2.修改uploadComplete中读取customSettings设置的upload_form,传递给uploadDone()函数

3.修改uploadDone函数加入参数id,用于传递要提交的表单的ID进行提交操作。

具体代码如下:

1.设置代码

custom_settings : {
progress_target : “fsUploadProgress”,
upload_successful : false,
upload_form:”Upload”
},

2.uploadComplete()

if (this.customSettings.upload_successful) {

this.setButtonDisabled(true);
uploadDone(this.customSettings.upload_form);
} else {

3.uploadDone()

function uploadDone(id) {
try {

document.getElementById(id).submit();
}

catch (ex) {
alert(“Error submitting form”);
}
}

赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏