2013-07-03 33 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

相关问题