safari/chrome/opera 可以在上传过程中发出 ajax 请求吗?

发布于 2024-09-08 04:54:19 字数 1603 浏览 1 评论 0原文

发出一个简单的 ajax 请求

function upload(){


            setInterval(function callMeOften()
            {
                $.ajax({
                   method: 'get',
                   url : 'uploadinfo.php?unique_id=<?php echo $some_uniq_id; ?>',
                   dataType : 'text',
                   success: function(text){ updatebar(text); },
                   error: function (XMLHttpRequest, textStatus, errorThrown) {
                      alert(XMLHttpRequest.status);
                      alert(XMLHttpRequest.responseText);
                   }
                });

            }, 5000);

        }

        function updatebar(per){

            $('#updateMe').animate({"width" : per});

        }

基本上我正在向 php 脚本

$unique_id = $_GET['unique_id'];
$progress = uploadprogress_get_info($unique_id);

if(function_exists("uploadprogress_get_info")) {


if (floor(($progress['bytes_total']/1024)/1024) > 100){

    echo "run";

} else {

    if ($progress['bytes_uploaded'] == 0 || $progress['bytes_total'] == 0){

        echo "100";

    } else {

        echo floor($progress['bytes_uploaded'] / $progress['bytes_total'] * 100);

    }

}

}

这个函数 upload();使用 onsubmit() 调用;文件上传表单的操作

<form id="something" onsubmit="upload();" action="status.php" enctype="multipart/form-data" method="post">

我使用相对路径,请求在 FF 和 IE 中有效,但在 chrome、safari 和 opera 中,上传过程中甚至不会触发 ajax 请求。

这是怎么回事?

编辑:最后我只是在一个单独的窗口中显示了上传进度,该窗口是使用 onsubmit 操作创建的,并重新调整大小并重新定位到屏幕中心,看起来不错,并且是迄今为止最简单的方法

Basically i am making a simple ajax request

function upload(){


            setInterval(function callMeOften()
            {
                $.ajax({
                   method: 'get',
                   url : 'uploadinfo.php?unique_id=<?php echo $some_uniq_id; ?>',
                   dataType : 'text',
                   success: function(text){ updatebar(text); },
                   error: function (XMLHttpRequest, textStatus, errorThrown) {
                      alert(XMLHttpRequest.status);
                      alert(XMLHttpRequest.responseText);
                   }
                });

            }, 5000);

        }

        function updatebar(per){

            $('#updateMe').animate({"width" : per});

        }

to a php script

$unique_id = $_GET['unique_id'];
$progress = uploadprogress_get_info($unique_id);

if(function_exists("uploadprogress_get_info")) {


if (floor(($progress['bytes_total']/1024)/1024) > 100){

    echo "run";

} else {

    if ($progress['bytes_uploaded'] == 0 || $progress['bytes_total'] == 0){

        echo "100";

    } else {

        echo floor($progress['bytes_uploaded'] / $progress['bytes_total'] * 100);

    }

}

}

This function upload(); is called using the onsubmit(); action of a file upload form

<form id="something" onsubmit="upload();" action="status.php" enctype="multipart/form-data" method="post">

I am using relative paths and the request works in FF and IE, but in chrome, safari and opera the ajax requests are not even fired while the upload is in progress.

What's going on?

EDIT: In the end i just showed the upload progress in a separate window that was created using the onsubmit action and re-sized and reposition to the center of the screen, looks alright and is by far the easiest way

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是有多爱你 2024-09-15 04:54:29

据我所知,一个服务器域可以有两个请求可以对浏览器处于活动状态。也就是说,如果您的服务器域名是“code.mydomain.com”,那么一次最多可以打开 2 个请求。在您的情况下,第一个是文件上传请求。您必须检查除了在指定浏览器中上传之外是否有任何其他活动请求。

As per I know there can be two request for one server domain can be active for the browser. That is if your server domain name is 'code.mydomain.com' then there can be atmost 2 request open at a time. In your case first one is file uploading request. You have to check do you have any other active request apart form uploading in specified browsers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文