Bootstrap fileinput 同步上传时回调处理

废话不多说直接看配置

注意:这里区分了是同步还是异步
同步的回调走 filebatchuploadsuccess(我把所有的都试了,才发现同步时会走这个方法)
异步的回调走 fileuploaded

配置项
uploadAsync: false,//同步上传

官方文档
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) {
     //异步上传成功结果处理

            }).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) {
     //同步上传回调
               
            });;

你可能感兴趣的:(Bootstrap fileinput 同步上传时回调处理)