我正在使用Hayageek jQuery Upload File Plugin上传带有其他表单数据的(单个和强制性)文件。这不是触发完整的页面发布,而是调用插件的startUpload
函数。
如果服务器对表单数据的验证检测到表单数据中的错误,则用户应该能够在(未更改)页面中更正此数据,然后再次按下“提交”按钮而无需再次选择已经选择的文件。
对于我检测到的插件,该插件创建了一个具有ID的临时表单,并且在首次首次上传文件后,该表单已删除,无法用于后续调用startUpload函数。
代码段:
self.uploadObj = $("#fileuploader").uploadFile({
url: lang["_INITFILEUPLOAD_URL_"],
fileName: "invoice",
multiple: false,
replaceFileInput: false,
allowedTypes: 'pdf',
autoSubmit: false,
maxFileSize: 5 * 1024 * 1024, // in bytes
maxFileCount: 1,
uploadStr: lang["_UPLOAD_INVOICE_"],
dragDropStr: lang["_UPLOAD_INVOICE_"],
doneStr: lang["_UPLOADED_INVOICE_"],
extErrorStr: lang["_UPLOAD_INVALID_EXTENSION_"],
sizeErrorStr: lang["_UPLOAD_INVALID_SIZE_"],
uploadErrorStr: lang["_UPLOAD_ERROR_"],
cancelStr: lang["_BUTTON_CANCEL_"],
doneStr: lang["_TXT_DONE_"],
onSuccess: function (uploadedFiles, data) {
if (data.Success && (data.ErrorMessages === null || data.ErrorMessages.length === 0)) {
self.uploadObj.reset(); // Clear the upload field if server validation is ok
$('.panel-body').html(''); // Remove the form
self.DisplayMessage([lang['_UPLOAD_SUCCESS_']], 'alert-success');
} else {
// --> Do not clear the form and the file upload form, just show the error
self.DisplayMessage(data.ErrorMessages, 'alert-warning');
}
},
onError: function (files, status, errorMessage, pd) {
self.uploadObj.reset();
self.DisplayMessage([errorMessage], 'alert-warning');
},
dynamicFormData: function () {
var data = {
AdditionalFormaData: {
Prop1: $('#prop1').val(),
Prop2: $('#prop2').val(),
Prop3: $('#prop3').val()
}
}
return data;
}
});