谷歌浏览器:XMLHtt prequest.send()不能同时做POST工作 [英] Google Chrome: XMLHttpRequest.send() not working while doing POST

查看:236
本文介绍了谷歌浏览器:XMLHtt prequest.send()不能同时做POST工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序,允许用户使用表单(POST请求)发送一个文件,并执行一系列GET请求,而该文件被上传到收集上传的状态信息

I'm working on an application that allows the user to send a file using a form (a POST request), and that executes a series of GET requests while that file is being uploaded to gather information about the state of the upload.

它工作正常,在IE和Firefox,但在Chrome和Safari没有这么多。

It works fine in IE and Firefox, but not so much in Chrome and Safari.

的问题是,即使发送()称为XMLHtt prequest对象上,没有正被请求如在提琴手可以看出。

The problem is that even though send() is called on the XMLHttpRequest object, nothing is being requested as can be seen in Fiddler.

要更具体地,事件处理程序被放置在表格的提交事件,则该放置一个超时函数调用的窗口上:

To be more specific, an event handler is placed on the "submit" event of the form, that places a timeout function call on the window:

window.setTimeout(startPolling, 10);

和在该功能startPolling序列开始,保持击发GET请求来接收从返回可用于更新UI文本/ JSON web服务状态更新。

and in this function "startPolling" sequence is started that keeps firing GET requests to receive status updates from a web service that returns text/json that can be used to update the UI.

这是一个限制(可能是安全的明智?)的基于WebKit的浏览器?这是一个Chrome浏览器的bug? (我看到在Safari虽然相同的行为)。

Is this a limitation (perhaps security-wise?) on WebKit based browsers? Is this a Chrome bug? (I'm seeing the same behaviour in Safari though).

推荐答案

我有完全相同的问题。目前我使用的iframe,这是有针对性的形式。这使得同时发布到执行的XHR请求。虽然这工作,它不降低正常,如果有人禁用了JavaScript。(我不能没有加载JS的iframe外的下页)因此,如果有人有一个更好的解决方案,我将不胜感激听到它。

I am having the exact same problem. At the moment i use an iframe, which is targeted in the form. That allows the xhr requests to be executed while posting. While that does work, it doesn't degrade gracefully if someone disables javascript.(I couldn't load the next page outside the iframe without js) So if someone has a nicer solution, i would be grateful to hear it.

下面的jQuery脚本供参考:

Here the jQuery script for reference:

$(function() {
$('form[enctype=multipart/form-data]').submit(function(){ 
    // Prevent multiple submits
    if ($.data(this, 'submitted')) return false;

    var freq = 500; // freqency of update in ms
    var progress_url = '{% url checker_progress %}'; // ajax view serving progress info 

    $("#progressbar").progressbar({
        value: 0
    });

    $("#progress").overlay({ 
        top: 272, 
        api: true,
        closeOnClick: false,
        closeOnEsc: false, 
        expose: { 
            color: '#333', 
            loadSpeed: 1000, 
            opacity: 0.9 
        }, 
    }).load();

    // Update progress bar
    function update_progress_info() {
        $.getJSON(progress_url, {}, function(data, status){ 
            if (data) {
                var progresse = parseInt(data.progress);
                $('#progressbar div').animate({width: progresse + '%' },{ queue:'false', duration:500, easing:"swing" }); 
            }
            window.setTimeout(update_progress_info, freq);
        });
    };
    window.setTimeout(update_progress_info, freq);

    $.data(this, 'submitted', true); // mark form as submitted.
});
});

这篇关于谷歌浏览器:XMLHtt prequest.send()不能同时做POST工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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