From c636f71fdf9db2c078118d7118752a1f176fe0a0 Mon Sep 17 00:00:00 2001 From: Neogavin Date: Wed, 28 Mar 2012 15:42:24 -0700 Subject: [PATCH 1/2] update jquery.iecors.js to prevent hangup in IE browsers when resource is not found. --- jquery.iecors.js | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/jquery.iecors.js b/jquery.iecors.js index 73af026..e52234c 100644 --- a/jquery.iecors.js +++ b/jquery.iecors.js @@ -2,46 +2,46 @@ // 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.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 ); From 70e62031360f6a3ef7176a589070312d89debf10 Mon Sep 17 00:00:00 2001 From: Neogavin Date: Thu, 29 Mar 2012 11:09:58 -0700 Subject: [PATCH 2/2] Just ran into this problem with IE9: http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/30ef3add-767c-4436-b8a9-f1ca19b4812e Added in fix for that as well. --- jquery.iecors.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jquery.iecors.js b/jquery.iecors.js index e52234c..4aec6ef 100644 --- a/jquery.iecors.js +++ b/jquery.iecors.js @@ -31,6 +31,7 @@ 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 );