Last active
August 29, 2015 13:57
-
-
Save derapU/9787351 to your computer and use it in GitHub Desktop.
add progress events for upload and download to jquery.ajax (xhr2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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