jQuery $.ajax extension XDomainRequest onprogress
Asked Answered
S

1

3

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.

Shoshonean answered 5/9, 2012 at 5:43 Comment(0)
S
4

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.

Shoshonean answered 6/9, 2012 at 0:36 Comment(2)
Excellent , can you handle the part of the repsonse you got? what is contained in the progressEvent?Shcherbakov
Progress event is defined as var progressEvent = {lengthComputable: false, loaded: 0, total: 0}; The only field that changes is 'loaded', because the content length is not computable (and so total = 0).Shoshonean

© 2022 - 2024 — McMap. All rights reserved.