php - blueimp Jquery上传插件: Large gap between last file progress hitting 100% and the done event

标签 php jquery file-upload progress-bar blueimp

所有的人都在问同样的问题,在所有主题和论坛中都没有答案。

$('#fileupload').fileupload({
    dropZone: $("#dragandrop"),
    pasteZone: $("#dragandrop"),
    //singleFileUploads: false,
    //progressInterval:50,
    //bitrateInterval:500,
    //forceIframeTransport: true,
    dataType: 'json',
    add: function (e, data) {
        data.submit();
    },
    progress: function (e, data) {
            //if (data.loaded == data.total ) {
            //    if (e.lengthComputable) {
            var progress = parseInt(data._progress.loaded / data.total * 100, 10);
            console.log(data.loaded + " " + data.total + " " + data.bitrate);
            $('#progress .bar').css('width', progress + '%');
        //}
    },
    always: function (e, data) {
        $('#progress .progress-bar').css('width',0);
    },
    done: function (e, data) {
        var result = data.result.data;
        //add the flash success message
        $('#trust-center-flash-message').html(result.message);
        //add the new images to the preview
        previewImages(result.attachments);
        return alert("done");
    }
});

我尝试了互联网上的所有解决方案。 我没有使用插件后端 php 类。

最佳答案

Kevin B says it ,正如您提到的那样:

The progress event only tracks the progress of the upload, not the progress of the request.

解决此问题的一种方法是更新我们对进度事件的响应方式。

One solution would be to have your progress bar stop at say, 90% then bump it to 100% in the done callback. simply multiply data.total by 1.1

    progress: function (e, data) {
        var progress = parseInt(data.loaded / (data.total*1.1) * 100, 10);
        var bar = data.context.children().children(".progress");
        $(bar).css("width", progress + "%");
    },

您也可以对事件“progressall”执行此操作,具体取决于您要修改的事件。

对于所有回调see the API ,以下是一些您可能感兴趣的内容

$('#fileupload')
...
.bind('fileuploadprogress', function (e, data) {/* ... /})
.bind('fileuploadprogressall', function (e, data) {/
... /})
.bind('fileuploadchunkdone', function (e, data) {/
... /})
...
.bind('fileuploadprocessdone', function (e, data) {/
... */})

关于php - blueimp Jquery上传插件: Large gap between last file progress hitting 100% and the done event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29277621/

相关文章:

php - 从 youtube video 获取视频源

php - 从 laravel 集合中获取模型数组

php - JQuery/AJAX 脚本有效但仍然显示通知?

php - 在 Woocommerce 中设置产品级别的最小、最大和步骤数量

php - MySQL PHP 在一段时间内随机排序?

php - 在 PHP 中链接静态方法?

javascript - 将数据存储到 DOM - 元素值与数据属性

php - Python 脚本将图像发送到 PHP

java - RestEasy代理框架文件上传

javascript - 如何使用FormData进行AJAX文件上传?