Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery $.ajax extension XDomainRequest onprogress

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.

like image 430
Rowan Avatar asked Dec 06 '25 02:12

Rowan


1 Answers

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.

like image 94
Rowan Avatar answered Dec 08 '25 14:12

Rowan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!