diff options
author | jaubourg <j@ubourg.net> | 2013-01-09 11:04:03 +0100 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2013-01-20 18:10:07 -0500 |
commit | 1ad874f3447cdba89d77cfe00b10d6f1d7dcea4e (patch) | |
tree | 448cbf7f46fa2bc6c09a48ab1ba813001e9db213 /src/ajax/script.js | |
parent | c373a499d39e35172f9b93af993681e4b5f0908b (diff) | |
download | jquery-1ad874f3447cdba89d77cfe00b10d6f1d7dcea4e.tar.gz jquery-1ad874f3447cdba89d77cfe00b10d6f1d7dcea4e.zip |
Further script transport cleanup, close gh-1123.
Diffstat (limited to 'src/ajax/script.js')
-rw-r--r-- | src/ajax/script.js | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/ajax/script.js b/src/ajax/script.js index b5d377571..a16e56dfa 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -25,30 +25,27 @@ jQuery.ajaxPrefilter( "script", function( s ) { }); // Bind script tag hack transport -jQuery.ajaxTransport( "script", function(s) { +jQuery.ajaxTransport( "script", function( s ) { // This transport only deals with cross domain requests if ( s.crossDomain ) { - var callback; + var script, callback; return { send: function( _, complete ) { - callback = function( type ) { - return function() { - callback = script.onload = script.onerror = null; - jQuery( script ).remove(); - if ( type ) { - complete( type === "success" ? 200 : 404, type ); + script = jQuery("<script>").prop({ + async: true, + charset: s.scriptCharset, + src: s.url + }).on( + "load error", + callback = function( evt ) { + script.off().remove(); + callback = null; + if ( evt ) { + complete( evt.type === "error" ? 404 : 200, evt.type ); } - }; - }; - var script = jQuery.extend( document.createElement("script"), { - async: true, - charset: s.scriptCharset, - src: s.url, - onload: callback("success"), - onerror: callback("error") - }); - callback = callback(); - document.head.appendChild( script ); + } + ); + document.head.appendChild( script[ 0 ] ); }, abort: function() { if ( callback ) { |