[英]Ajax loading progress bar with percentage
I am working with an image uploader. 我正在与图像上传器合作。 The issue is that the image uploader only shows me an ajax progress bar image but without any percentage. 问题是图像上传器仅显示一个ajax进度条图像,但没有任何百分比。
How can I implement a percentage to the code below (which is relevant to the progress bar)? 如何在下面的代码中实现一个百分比(与进度条有关)?
jQuery.itemForm.submitFormIfNotImageLoading = function(loadingTime) { jQuery.itemForm.submitFormIfNotImageLoading = function(loadingTime){
if (jQuery.uploaderPreviewer.loadingImages()) {
if(loadingTime > $.itemForm.loadingTimeout) {
var settings = {
title: $.itemForm.messages.timeoutTitle,
message: $.itemForm.messages.timeoutMessage,
buttons: { 'OK': function() { $(this).dialog("close"); } }
};
$.globalFunctions.openDialog(settings);
}
else {
loadingTime += $.itemForm.checkingIntervalTime;
var progressBarValue = $("#progressbar").progressbar('value')
+ $.itemForm.progressBarInterval;
$("#progressbar").progressbar('value', progressBarValue);
var recursiveCall = "$.itemForm.submitFormIfNotImageLoading(" + loadingTime + ")";
setTimeout(recursiveCall, $.itemForm.checkingIntervalTime);
}
}
else {
submitForm();
}
};
function showImageLoadingMessage() {
var options = {
title: $.itemForm.messages.savingTitle,
message: $.itemForm.messages.savingMessage
};
$.globalFunctions.openDialog(options);
$("#progressbar").progressbar({
value: 0
});
var progressBarInterval = $.itemForm.checkingIntervalTime * 100 / $.itemForm.loadingTimeout;
if (progressBarInterval != Number.NaN) {
$.itemForm.progressBarInterval = Math.floor(progressBarInterval);
}
};
Actually, due to the fact that the communication is client-server without a persistent connection you can't display percentage with ajax in a non-HTML5 browser . 实际上,由于通信是没有持久连接的客户端-服务器,因此您无法在非HTML5浏览器中 使用 ajax显示百分比。
You should consider (if you want to maintain the compatibility) to use some flash uploaders that should work pretty well for your needing ( this is the first that I've found) 您应该考虑(如果要保持兼容性)使用一些应该可以很好满足您需求的Flash上传器( 这是我发现的第一个)
You can alternatively use a persistent connection method like COMET or similar, but it's hardly compatible with the older browsers anyway. 您也可以使用诸如COMET或类似方法的持久连接方法,但是无论如何它都与旧版浏览器几乎不兼容。
If you are an "open source" friendly guy, I think that it's better if you use HTML5 progress bar and an alternative without progress for people with incompatible browsers (If it's something like a jQuery plugin, you will anyway have the majority of your users that use an HTML5 browser) 如果您是一个“开放源代码”友好的人,我认为使用HTML5进度栏和不带浏览器的浏览器不兼容的情况会更好(对于像jQuery插件这样的人,无论如何您都会拥有大多数用户使用HTML5浏览器)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.