Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save derapU/9787351 to your computer and use it in GitHub Desktop.

Select an option

Save derapU/9787351 to your computer and use it in GitHub Desktop.
add progress events for upload and download to jquery.ajax (xhr2)
jQuery( function ( $ ) {
var originalXhr = $.ajaxSettings.xhr;
$.ajaxSetup( {
progress: function () {},
uploadprogress: function () {},
xhr: function () {
var req = originalXhr(),
self = this;
if ( req ) {
if ( typeof req.addEventListener == "function" ) {
req.addEventListener( "progress", function ( e ) {
self.progress( e );
}, false );
}
if ( typeof req.upload.addEventListener == "function" ) {
req.upload.addEventListener( "progress", function ( e ) {
self.uploadprogress( e );
}, false );
}
}
return req;
}
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment