2012-07-05 113 views
2

我正在使用圖片上傳器。問題在於圖片上傳器僅向我顯示ajax進度條圖片,但沒有任何百分比。Ajax加載進度條百分比

如何在下面的代碼中實現百分比(與進度欄相關)?

jQuery.itemForm.submitFormIfNotImageLoading =函數(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); 
    } 
}; 
+0

您正在尋找HTML5解決方案還是舊的學校方法? – VAShhh 2012-07-05 13:30:18

+0

我正在尋找一個老派的方法 – techAddict82 2012-07-05 14:14:41

回答

1

實際上,由於這一事實,該通信是客戶端 - 服務器沒有持久連接你不能顯示百分比 ajax在非HTML5瀏覽器

你應該考慮(如果你想保持兼容性)使用一些閃光的上傳應該起到很好的爲你的需要(this是第一次,我已經找到)

您也可以使用持久像COMET或類似的連接方法,但它與舊版瀏覽器無法兼容。

如果你是一個「開源」友好的傢伙,我認爲如果你使用HTML5進度條和其他替代瀏覽器的人沒有進步,那麼它會更好一些(如果它是一個jQuery插件,你將擁有大多數使用HTML5瀏覽器的用戶)