gpt4 book ai didi

jquery - Blueimp上传插件进度条错误

转载 作者:行者123 更新时间:2023-12-01 04:13:51 25 4
gpt4 key购买 nike

我有一个表单,我正在其中使用 blueimp 上传插件上传文件。上传过程工作正常。我想要的只是为上传事件添加一个进度条。我尝试使用 blueimp 文档中指定的 progressall 回调,但我得到的只是 100% 加载,因为 data.loaded 始终等于 data.total.

我发现该插件仅在 done 回调之后处理 progressall 回调,并且在 done 回调中我采取了几个操作地点。

请参阅下面的示例:

$("#uploadFile" + docId).fileupload({
url: my url to the upload script,
dataType : 'json',
type: 'POST',
formAcceptCharset: 'utf-8',
forceIframeTransport: true,
progressInterval: 100,
bitrateInterval: 500,
autoUpload: true,
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress'+docId+' .bar').css(
'width',
progress + '%'
).text(progress + '%');
},
send : function(e, data) {
if(data.files[0].size <= 9000000000){
var docId = $(this).attr("data-course-id");
$("#uploadFileForm"+docId+" .uploadProgress").removeClass("hidden");
$("#uploadFeedback").html("");
}else{
$("#uploadFeedback").html(file is too big);
return false;
}
},
fail : function(e, data) {
console.log("error = " + data.errorThrown);
return false;
},
done : function(e, data) {
var metaSuggestions = data.result;

$("#uploadFileForm"+docId+" .uploadProgress").addClass("hidden");

//enable save button
$("#fileUploadSubmit"+ docId).removeClass("buttonDisabled");
$("#fileUploadSubmit"+ docId).removeAttr("disabled");

//populate fields
$("#fileUploadedId"+docId).val(metaSuggestions.uploadedDocId);
$("#fileDuration"+docId).val(metaSuggestions.lengthMiliseconds/1000 + " s");
$("#fileMediaType"+docId).val(metaSuggestions.mediaType);

//change cancel action
$("#fileUploadCancel"+ docId).unbind("click").click(function(){

var successCallbackCancel = function(data){
$("#uploadFileForm"+ docId).addClass("hidden");
}

var errorCallbackCancel = function(error){
console.log(error);
}

cancelAddFile(contextPath, docId, metaSuggestions.uploadedDocId, successCallbackCancel, errorCallbackCancel);
});

$("#fileUploadSubmit"+docId).unbind('click').click(function(){

var successCallbackSubmit = function(data){
$("#uploadFileForm" + docId).addClass("hidden");

//append file to files container
var fileContainer = $("#files" + docId);

appendFilesToContainer(data, docId);
}

var errorCallbackSubmit = function(error){
console.log(error);
}

submitFiles(contextPath, docId, metaSuggestions, successCallbackSubmit, errorCallbackSubmit);
});
console.log("file done");
}
});

最佳答案

我设法通过注释掉 forceIframeTransport: true 来修复它。现在进度条可以正常工作了!

关于jquery - Blueimp上传插件进度条错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16894912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com