繁体   English   中英

带有百分比的Ajax加载进度栏

[英]Ajax loading progress bar with percentage

我正在与图像上传器合作。 问题是图像上传器仅显示一个ajax进度条图像,但没有任何百分比。

如何在下面的代码中实现一个百分比(与进度条有关)?

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);
    }
};

实际上,由于通信是没有持久连接的客户端-服务器,因此您无法非HTML5浏览器中 使用 ajax显示百分比。

您应该考虑(如果要保持兼容性)使用一些应该可以很好满足您需求的Flash上​​传器( 是我发现的第一个)

您也可以使用诸如COMET或类似方法的持久连接方法,但是无论如何它都与旧版浏览器几乎不兼容。

如果您是一个“开放源代码”友好的人,我认为使用HTML5进度栏和不带浏览器的浏览器不兼容的情况会更好(对于像jQuery插件这样的人,无论如何您都会拥有大多数用户使用HTML5浏览器)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM