繁体   English   中英

$ .get功能未在Chrome中运行,但在IE和FireFox中运行

[英]$.get function not running in Chrome but working in IE and FireFox

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

有没有人知道什么是错的?

谢谢!

在Chrome中转到开发工具(选项 - >工具 - >开发人员工具)并查看网络面板。 调用$ .get方法后,您将看到您的请求和结果 - 您可以看到它是否失败(例如,如果发生404),那么chrome可能不会设置地址,或者发送数据/返回数据不好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM