Skip to content

Instantly share code, notes, and snippets.

@brokensandals
Created January 30, 2015 04:44
Show Gist options
  • Save brokensandals/be6911a3f7d06f93b15d to your computer and use it in GitHub Desktop.
Save brokensandals/be6911a3f7d06f93b15d to your computer and use it in GitHub Desktop.
1,9c1
< var xhrCallbacks,
< // #5280: Internet Explorer will keep connections alive if we don't abort on unload
< xhrOnUnloadAbort = window.ActiveXObject ? function() {
< // Abort all pending requests
< for ( var key in xhrCallbacks ) {
< xhrCallbacks[ key ]( 0, 1 );
< }
< } : false,
< xhrId = 0;
---
> /**
11,16c3
< // Functions to create xhrs
< function createStandardXHR() {
< try {
< return new window.XMLHttpRequest();
< } catch( e ) {}
< }
---
> This is derived from the file xhr.js in jQuery-1.8.0, which is licensed as follows:
18,22c5,6
< function createActiveXHR() {
< try {
< return new window.ActiveXObject( "Microsoft.XMLHTTP" );
< } catch( e ) {}
< }
---
> Copyright 2012 jQuery Foundation and other contributors
> http://jquery.com/
24,45c8,29
< // Create the request object
< // (This is still attached to ajaxSettings for backward compatibility)
< jQuery.ajaxSettings.xhr = window.ActiveXObject ?
< /* Microsoft failed to properly
< * implement the XMLHttpRequest in IE7 (can't request local files),
< * so we use the ActiveXObject when it is available
< * Additionally XMLHttpRequest can be disabled in IE7/IE8 so
< * we need a fallback.
< */
< function() {
< return !this.isLocal && createStandardXHR() || createActiveXHR();
< } :
< // For all other browsers, use the standard XMLHttpRequest object
< createStandardXHR;
<
< // Determine support properties
< (function( xhr ) {
< jQuery.extend( jQuery.support, {
< ajax: !!xhr,
< cors: !!xhr && ( "withCredentials" in xhr )
< });
< })( jQuery.ajaxSettings.xhr() );
---
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
>
> */
>
> var xhrId = 0;
50c34
< jQuery.ajaxTransport(function( s ) {
---
> jQuery.ajaxTransport('+blob', function( s ) {
98a83,84
> xhr.responseType = 'blob';
>
127,129d112
< if ( xhrOnUnloadAbort ) {
< delete xhrCallbacks[ handle ];
< }
142,154c125,126
< xml = xhr.responseXML;
<
< // Construct response list
< if ( xml && xml.documentElement /* #4958 */ ) {
< responses.xml = xml;
< }
<
< // When requesting binary data, IE6-9 will throw an exception
< // on any attempt to access responseText (#11426)
< try {
< responses.text = xhr.responseText;
< } catch( _ ) {
< }
---
>
> responses.blob = xhr.response;
171c143
< status = responses.text ? 200 : 404;
---
> status = (responses.blob || responses.text) ? 200 : 404;
199,208d170
< if ( xhrOnUnloadAbort ) {
< // Create the active xhrs callbacks list if needed
< // and attach the unload handler
< if ( !xhrCallbacks ) {
< xhrCallbacks = {};
< jQuery( window ).unload( xhrOnUnloadAbort );
< }
< // Add to list of active xhrs callbacks
< xhrCallbacks[ handle ] = callback;
< }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment