我正在使用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