我已经在github插件上打开了一个问题,但是它似乎不是很活跃,所以我也在这里问。
我正在通过ajax发送我的文件,但是当上传失败(因为高度太小)时,我没有收到真正的错误消息,但是我从ajax url中得到了一个错误,但是这个错误没有意义,因为没有发送任何内容。我认为不应该调用ajax路由,但是无论如何,我尝试使用'fileuploaderror‘,我确实得到了想要的错误,但是我不知道如何显示它们。在fileuploaderror事件中肯定有一种简单的方法,但我不知道。有人能帮我这个忙吗?
问题链接 x- 插件页面
谢谢
$("#id").fileinput({
uploadUrl: "/ajax/snippet/image/send/78", // server upload action
deleteUrl: "/ajax/snippet/image/remove/",
uploadAsync: false,
showUpload: false, // hide upload button
showRemove: false, // hide remove button
maxFileCount: maxFile,
browseOnZoneClick: true,
language: "fr",
minImageWidth: 150,
minImageHeight: 150,
allowedFileExtensions: ["jpg", "jpeg", "gif", "bmp", "png"],
multiple: true,
maxFileSize: 5000,
uploadExtraData: function (previewId, index) {
return {key: index};
},
initialPreviewAsData: true,
overwriteInitial: false,
}).on("filebatchselected", function (event, files) {
// trigger upload method immediately after files are selected
$(this).fileinput("upload");
}).on('fileuploaderror', function (event, data, msg) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
// get message
alert(msg);
});
}发布于 2016-12-05 08:26:31
好的,我得到了答案,在我的“文件批选择”事件中,我强迫上传。
我需要检查我是否有有效的文件上传第一。
$("#id").fileinput({
uploadUrl: "/ajax/snippet/image/send/78", // server upload action
deleteUrl: "/ajax/snippet/image/remove/",
uploadAsync: false,
showUpload: false, // hide upload button
showRemove: false, // hide remove button
maxFileCount: maxFile,
browseOnZoneClick: true,
language: "fr",
minImageWidth: 150,
minImageHeight: 150,
allowedFileExtensions: ["jpg", "jpeg", "gif", "bmp", "png"],
multiple: true,
maxFileSize: 5000,
uploadExtraData: function (previewId, index) {
return {key: index};
},
initialPreviewAsData: true,
overwriteInitial: false,
}).on("filebatchselected", function (event, files) {
// trigger upload method immediately after files are selected
var filesStack = $('#input-id').fileinput('getFileStack');
if (filesStack.length > 0) {
$(this).fileinput("upload");
}
});
}https://stackoverflow.com/questions/40916632
复制相似问题