【问题标题】:$.get function not running in Chrome but working in IE and FireFox$.get 函数不在 Chrome 中运行,但在 IE 和 FireFox 中运行
【发布时间】:2013-06-30 19:23:45
【问题描述】:

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

有没有人知道什么地方出了问题?

谢谢!

【问题讨论】:

  • 您是否看到控制台中传递的信息?

标签: php javascript jquery google-chrome


【解决方案1】:

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

【讨论】:

  • 抱歉,本来是要评论的 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多