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.

Rowan
  • 71
  • 7

1 Answers1

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.

Rowan
  • 71
  • 7
  • Excellent , can you handle the part of the repsonse you got? what is contained in the progressEvent? – Edmondo Apr 09 '13 at 09:18
  • 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). – Rowan Mar 04 '14 at 02:55