2013-07-03 32 views
3

我正在使用php POST將文件上載到服務器的站點上工作,並且正在嘗試向上傳中添加進度欄。 我遵循這個指南:

http://www.ultramegatech.com/2010/10/create-an-upload-progress-bar-with-php-and-jquery/

它工作在IE和Firefox很大。但進度條永遠不會在Chrome中更新。

該函數被調用的超時時間爲「500」。

function updateProgress(id) { 
    var time = new Date().getTime(); 
    // Make a GET request to the server 
    // Pass our upload identifier as a parameter 
    // Also pass current time to prevent caching 
    $.get('progressbar.php', { uid: id, t: time }, function (data) { 
     // Get the output as an integer 
     var progress = parseInt(data, 10); 
     if (progress < 100 || !started) { 
      var div = document.getElementById('statusfield'); 
      div.innerHTML = progress + '%'; 
      // Determine if upload has started 
      started = progress < 100; 

      // If we aren't done or started, update again 
      updateProgress(id); 
     } 
     if (progress > 99) { 
      var div = document.getElementById('statusfield'); 
      div.innerHTML = 'Komprimerar fil...'; 
     } 
     // Update the progress bar percentage 
     // But only if we have started 
     started && pbar.progressbar('value', progress); 
    }); 
} 

該函數調用.php文件「progressbar.php」,它以百分比數字的形式傳遞上傳進度。

progressbar.php:

<?php 
    if (isset($_GET['uid'])) { 
     // Fetch the upload progress data 
     $status = uploadprogress_get_info($_GET['uid']); 
     if ($status) { 
      // Calculate the current percentage 
      echo round($status['bytes_uploaded']/$status['bytes_total']*100); 
     } 
     else { 
      // If there is no data, assume it's done 
      echo 100; 
     } 
    } 
?> 

我已經測試Chrome的代碼和功能 「的UpdateProgress」 被調用。但它永遠不會通過:

$.get('progressbar.php', { uid: id, t: time }, function 

有沒有人有任何線索可能是錯的?

謝謝!

+1

您是否看到信息在控制檯中傳遞? – JonathanRomer

回答

1

在鉻去開發工具(選項 - >工具 - >開發工具),看看網絡面板。一旦$ .get方法被調用,你會看到你的請求和結果 - 你可以看到它是否失敗(例如,如果發生404),所以也許鉻不設置地址,因爲它應該或如果發送的數據/返回數據不好。

+0

+1開發工具,但-1,因爲這應該是一個評論;) – TecHunter

+0

對不起,它的目的是成爲一個評論:) – Kristijan

相關問題