Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update jquery.iecors.js to prevent hangup in IE browsers when resource i... #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions jquery.iecors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,47 @@
// Create the request object
// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xdr = function() {
return (window.XDomainRequest ? new window.XDomainRequest() : null);
return (window.XDomainRequest ? new window.XDomainRequest() : null);
};

// Determine support properties
(function( xdr ) {
jQuery.extend( jQuery.support, { iecors: !!xdr });
jQuery.extend( jQuery.support, { iecors: !!xdr });
})( jQuery.ajaxSettings.xdr() );

// Create transport if the browser can provide an xdr
if ( jQuery.support.iecors ) {

jQuery.ajaxTransport(function( s ) {
var callback;

return {
send: function( headers, complete ) {
var xdr = s.xdr();

xdr.onload = function() {
var headers = { 'Content-Type': xdr.contentType };
complete(200, 'OK', { text: xdr.responseText }, headers);
};

// Apply custom fields if provided
if ( s.xhrFields ) {
xhr.onerror = s.xhrFields.error;
xhr.ontimeout = s.xhrFields.timeout;
}

xdr.open( s.type, s.url );

// XDR has no method for setting headers O_o

xdr.send( ( s.hasContent && s.data ) || null );
},

abort: function() {
xdr.abort();
}
};
});
}
if ( jQuery.support.iecors ) {
jQuery.ajaxTransport(function( s ) {
return {
send: function( headers, complete ) {
var xdr = s.xdr();

xdr.onload = function() {
var headers = { 'Content-Type': xdr.contentType };
complete(200, 'OK', { text: xdr.responseText }, headers);
};

// Apply custom fields if provided
if(s.xhrFields) {
xdr.onerror = s.xhrFields.error;
xdr.ontimeout = s.xhrFields.timeout;
} else {
//Needed to prevent hangup when not defined in IE
xdr.onerror = function() {complete(404, 'Not Found')}
xdr.ontimeout = function() {complete(408, 'Request Time-Out')}
}
xdr.onprogress = function() {};
xdr.timeout = 5000;
xdr.open( s.type, s.url );

// XDR has no method for setting headers O_o

xdr.send( ( s.hasContent && s.data ) || null );
},

abort: s.xdr().abort

};
});
}
})( jQuery );