X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax%2Fscript.js;h=b0e576f27742d6137d5676e27d45d6c0ed0bb4ec;hb=f74b84498987ace9bbbc3c041607016a23ff251e;hp=0db0de6c7ef7d56dfc4047018028efd870a249a8;hpb=c43b078c6911027fd4124d542446ad0098662f6a;p=jquery.git diff --git a/src/ajax/script.js b/src/ajax/script.js index 0db0de6..b0e576f 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -1,7 +1,7 @@ (function( jQuery ) { -// Install text to script executor -jQuery.extend( true, jQuery.ajaxSettings , { +// Install script dataType +jQuery.ajaxSetup({ accepts: { script: "text/javascript, application/javascript" @@ -14,20 +14,24 @@ jQuery.extend( true, jQuery.ajaxSettings , { converters: { "text script": jQuery.globalEval } -} ); -// Bind script tag hack transport -jQuery.ajax.transport("script", function(s) { +// Handle cache's special case and global +}).ajaxPrefilter("script", function(s) { - // Handle cache special case if ( s.cache === undefined ) { s.cache = false; } - // This transport only deals with cross domain get requests - if ( s.crossDomain && s.async && ( s.type === "GET" || ! s.data ) ) { - + if ( s.crossDomain ) { + s.type = "GET"; s.global = false; + } + +// Bind script tag hack transport +}).ajaxTransport("script", function(s) { + + // This transport only deals with cross domain requests + if ( s.crossDomain ) { var script, head = document.getElementsByTagName("head")[0] || document.documentElement; @@ -47,7 +51,7 @@ jQuery.ajax.transport("script", function(s) { script.src = s.url; // Attach handlers for all browsers - script.onload = script.onreadystatechange = function( _ , statusText) { + script.onload = script.onreadystatechange = function( _ , isAbort ) { if ( ! script.readyState || /loaded|complete/.test( script.readyState ) ) { @@ -59,10 +63,13 @@ jQuery.ajax.transport("script", function(s) { head.removeChild( script ); } + // Dereference the script script = 0; - // Callback - callback( statusText ? 0 : 200, statusText || "success" ); + // Callback if not abort + if ( ! isAbort ) { + callback( 200, "success" ); + } } }; // Use insertBefore instead of appendChild to circumvent an IE6 bug. @@ -70,9 +77,9 @@ jQuery.ajax.transport("script", function(s) { head.insertBefore( script, head.firstChild ); }, - abort: function(statusText) { + abort: function() { if ( script ) { - script.onload( 0 , statusText ); + script.onload(0,1); } } };