本文介绍了jQuery $ .ajax扩展XDomainRequest onprogress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本:

我想得到与:

长版:

我想创建一个jQuery扩展,为$ .ajax对象添加一个进程方法,该方法适用于IE8& IE9的XDomainRequest对象。

I want to create a jQuery extension that adds a progress method to the $.ajax object and which works with IE8 & IE9's XDomainRequest object.

目前,使用上述插件,我只能为XMLHttpRequest对象定义进度事件回调处理程序。

Currently, using the above plugins, I can only define progress event callback handlers for XMLHttpRequest objects.

但是,XDomainRequest还提供onprogress事件。我基本上需要XDomainRequest的包装器。例如。 progressEvent.length对应于xdr.responseText.length。

However, XDomainRequest also provides an onprogress event. I basically need a wrapper for XDomainRequest. Eg. progressEvent.length would correspond to xdr.responseText.length.

我很感激有关从哪里开始的任何建议。

I'd appreciate any suggestions on where to begin.

推荐答案

好吧,我解决了这个问题。我最终要求通过ajax传输器实现XDomainRequest。

Well, I worked this out. I ended up forking ajaxHooks which implements XDomainRequest via an ajax transporter.

我添加了对名为progress的onprogress事件回调的支持,该回调可以用原始的ajax对象定义。

I added support for an onprogress event callback named "progress" which can be defined with the original ajax object.

按照W3C Standard,progressEvent.lengthComputable = false因为我们无法获得内容长度,所以progressEvent.total = 0;

As per the W3C Standard, progressEvent.lengthComputable = false because we can't get the content length, and so progressEvent.total = 0;

参见下面的示例:

$(document).ready(function(){

    var download_url = YOUR_URL;

    $.ajax({

        url: download_url,
        cache: false,
        progress: function(jqXHR, progressEvent) {

            console.log(progressEvent.loaded);

        }
    })
});

查看我的。

这篇关于jQuery $ .ajax扩展XDomainRequest onprogress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 13:11