注意:這裏區分了是同步仍是異步
同步的回調走 filebatchuploadsuccess(我把全部的都試了,才發現同步時會走這個方法)
異步的回調走 fileuploadedhtml
配置項
uploadAsync: false,//同步上傳bootstrap
官方文檔
http://bootstrap-fileinput.com/events.html異步
//初始化頭像上傳插件
$("#portrait").fileinput({
language: 'zh', //設置語言
showUpload: false,
elErrorContainer: '#kartik-file-errors',
allowedFileExtensions: ["jpg", "JPG", "jpeg", "JPEG", "png", "gif"],
dropZoneEnabled: false,
maxFileCount: 1,
uploadAsync: false,//異步上傳
uploadUrl: "../upload/file/1",//圖片上傳的url
enctype:'multipart/form-data',
previewFileIcon: "",
maxImageWidth: 200,
resizeImage: false,
showPreview: false
}).on("filebatchselected", function (event, data) {//選擇即上傳
if (data.length == 0) {
return;
}
}).on('fileuploaded', function (event, data) {//異步上傳成功結果處理url
}).on('fileerror', function (event, data, msg) {//異步上傳失敗結果處理
console.log(event, data, msg);
}).on('fileuploaderror', function (event, data, msg) {//異步上傳失敗結果處理
console.log(event, data, msg);
}).on('filebatchuploadsuccess', function(event,data,previewId,index) {//同步上傳回調
});;
原文連接:https://blog.csdn.net/zhaohan___/article/details/94434399.net