我正在使用Jquery fileupload插件上传文件。我的问题是,当由于某些错误而我返回JSON错误时我希望删除我之前选择的文件:
$('#fileUpload').fileupload("destroy");
这是我的代码看起来像
$('#fileUpload').fileupload({
autoUpload: false,
dataType: 'json',
change: function (e, data) {
/******************************* Applying file validations ********************************************/
var allowedExtensions = "";
@if (Model.DocumentType.ToLower() == "cr")
{
@:allowedExtensions = ["jpg", "jpeg", "png", "doc", "docx", "xls", "xlsx", "xlsm", "pdf", "txt", "rtf", "msg", "csv", "ppt", "pptx", "tar", "xml", "7zip", "zip", "zipx", "bmp", "tif", "tiff"];
}
else
{
@:allowedExtensions = ['jpg', 'jpeg', 'pdf', 'doc', 'docx', 'xls', 'xlsx'];
}
var value = data.files[0].name,
file = value.toLowerCase(),
extension = file.substring(file.lastIndexOf('.') + 1);
if ($.inArray(extension, allowedExtensions) == -1) {
$("#invoiceUploadForm").find('#fileUpload').val('');
data.files = [];
@if (Model.DocumentType.ToLower() == "cr")
{
}
else
{
@:kendoAlert('Please select only files of type JP(E)G, PDF, DOC(X) or XLS(X)');
}
}
else {
if (UploadedFileNameValidation(value)) {
$("#invoiceUploadForm").find('#fileUploadLink').addClass('disabled').text('File Selected...');
}
else {
kendoAlert("File name contains special character. Please remove special characters.");
return;
}
}
var fileName = '';
if (data.files != undefined && data.files.length > 0) {
fileName = data.files[0].name;
}
$('#uploadedFileName').val(fileName);
},
add: function (e, data) {
if (UploadedFileNameValidation(data.originalFiles[0].name)) {
$("#invoiceUploadForm").find('#invoiceCreateBtn').click(function () {
if (validator.validate() && $('#ContentId').val() == 0) {
if ($('#InvoiceDate').length) {
if (validateDate) {
$(".k-tooltip").hide();
if (new Date(tmpinvoiceDate) > new Date()) {
ExecuteMethodAfterOkClick('some message', innerUpdateFunc);
}
else {
innerUpdateFunc();
}
}
else {
$(".k-tooltip").show();
}
} else {
innerUpdateFunc();
}
}
});
$("#invoiceUploadForm").find('#invoiceSubmitBtn,#crpcSubmitBtn').click(function () {
if (validator.validate() && $('#ContentId').val() == 0) {
if (new Date(tmpinvoiceDate) > new Date()) {
}
else {
innerUpdateFunc();
}
} else {
innerUpdateFunc();
}
}
});
function innerUpdateFunc() {
kendo.ui.progress($("body"), true);
var values = $("#invoiceUploadForm").serializeArray();
data.formData = values;
data.submit();
}
}
},
done: function (e, data) {
//kendo.ui.progress($("body"), false);
var result = data.result;
if (result.saved) {
if (shouldSubmitInvoice) {
//kendoAlert(result.Msg, 'Success!', function () {
// SubmitInvoice(result);
//});
SubmitInvoice(result);
}
else {
PostSuccessActions(result);
@*kendoAlert(result.Msg, 'Success!', function () {
});*@
}
}
else {
kendoAlert(result);
$("#invoiceUploadForm").find('#fileUploadLink').removeClass('disabled').text('Upload');
$("input#fileUpload").prop("disabled", false);
// I have tried multiple solutions here but none of them worked
$('#fileUpload').fileupload("destroy");//not working
$('#fileUpload').val(""); //not worked
$('#fileUpload').files=null;//not worked
$('#fileUpload').replaceWith($('#fileUpload').clone(true));//not worked
}
}
});
如何删除从插件数据中选择的上一个图像并选择一个新图像?