$ .get函数不在Chrome中运行,但在IE和FireFox中工作 [英] $.get function not running in Chrome but working in IE and FireFox

查看:112
本文介绍了$ .get函数不在Chrome中运行,但在IE和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();
//向服务器发出GET请求
//将我们的上传标识符作为参数传递
//同时传递当前时间以防止缓存
$ .get('progressbar。 php',{uid:id,t:time},function(data){
//获取输出为整数
var progress = parseInt(data,10);
if进度< 100 ||!started){
var div = document.getElementById('statusfield');
div.innerHTML = progress +'%';
//确定上传是否存在开始
开始=进度<100;

//如果我们没有完成或开始,再次更新
updateProgress(id);
}
if(progress> 99){
var div = document.getElementById('statusfield');
div.innerHTML ='Komprimerar fil ...';
}
//更新进度条百分比
//但是只有当我们已经开始
时开始&& pbar.progressbar('value',progress);
});
}

该函数调用通过上传的.php文件progressbar.php

progressbar.php:

  <?php 
if(isset($ _ GET ['uid'])){
//获取上传进度数据
$ status = uploadprogress_get_info($ _ GET ['uid']) ;
if($ status){
//计算当前百分比
echo round($ status ['bytes_uploaded'] / $ status ['bytes_total'] * 100);
}
else {
//如果没有数据,假设它已完成
echo 100;
}
}
?>

我已经在chrome中测试了代码,并调用了函数updateProgress。但它永远不会超过:

$ $ $。get('progressbar.php',{uid:id,t:time} ,函数

有没有人有任何线索可能会出错?



谢谢!

解决方案

在chrome中去开发工具(Options - > Tools - > Developer tools)并查看网络面板,一旦$ .get方法被调用,你将看到你的请求和结果 - 你可以看到它是否失败(例如,如果404发生),所以也许铬不设置地址,因为它应该或者发送的数据/返回数据不正确。


I'm working on a site that uses php POST to upload files to a server and i'm trying to add a progress bar to the uploads. I followed this guide:

http://www.ultramegatech.com/2010/10/create-an-upload-progress-bar-with-php-and-jquery/

It works great in ie and firefox. But the progressbar never updates in chrome.

This function gets called with a timeout of "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);
    });
}

This function calls the .php file "progressbar.php" which passes the upload progress back as a percentage number.

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;
        } 
    }
?>

I have tested the code in chrome and the function "updateProgress" gets called. But it never gets past the:

$.get('progressbar.php', { uid: id, t: time }, function

Does anyone have any clue on what could be wrong?

Thanks!

解决方案

In chrome go to dev tools (Options -> Tools -> Developer tools) and look at the network panel. Once the $.get method is called you will see your request and the result - you can see if it fails (for example if a 404 happens) so maybe chrome doesn't set the address as it should or if the sent data / return data isn't ok.

这篇关于$ .get函数不在Chrome中运行,但在IE和FireFox中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆