Accessing the XHR object in jQuery's $.ajax
Its useful and somtimes necessary to access the native XHR when using $.ajax. When your in this spot - and still want jquery to do the heavy lifting, do this:
var xhr = $.ajaxSettings.xhr();
//Do what you want with the XHR Object. For Example:
xhr.upload.addEventListener( function( event ) {
//CODE!!!
}, false );
//Store the XHR in a closure.
function xhrProvider() {
return xhr;
}
//Then when using $.ajax specifiy a custom xhr like this:
$.ajax( {
url: 'http://w00wz3rs.com',
xhr: xhrProvider
} );
Written by Robert Martone
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#