在所有的线程和论坛中,所有的人都在问同样的问题没有答案。
$('#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所说,正如你所提到的:
进度事件只跟踪上传的进度,而不是请求的进度。
解决此问题的一种方法是更新我们对进度事件的响应方式。
一个解决方案是让你的进度条停在90%,然后在done回调中将其提高到100%。只需将data.total乘以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"执行此操作,具体取决于要修改的事件。
对于所有的回调,请参阅API,下面是一些可能会引起您兴趣的
$('#fileupload')
…
.bind('filiploadprogress',函数(e,data){/*…/})
.bind('filiploadprogressall',函数(e,data){/…/})
.bind('filiploadchunkdone',函数(e,数据){/…/})
…
.bind('filiploadprocessdone',函数(e,数据){/…*/})