jQuery $.ajax extension XDomainRequest onprogress

霸气de小男生 提交于 2019-12-07 19:46:00

问题


The short version:

I want to get this to work with this:

The long version:

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.

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

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.


回答1:


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

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

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

See example below:

$(document).ready(function(){

    var download_url = YOUR_URL;

    $.ajax({

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

            console.log(progressEvent.loaded);

        }
    })
});

See my ajaxHooks fork here.



来源:https://stackoverflow.com/questions/12275128/jquery-ajax-extension-xdomainrequest-onprogress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!