我正在使用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
有没有人有任何线索可能是错的?
谢谢!
您是否看到信息在控制台中传递? – JonathanRomer