From: Richard Gibson Date: Sun, 2 Dec 2012 05:14:25 +0000 (-0500) Subject: Fix #12838: hook point for non-jQuery.ajax synchronous script fetch/execute in domMan... X-Git-Tag: 1.10.0-beta1~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0100becc91167cfe92aefca52dd9ba29eddb259e;p=jquery.git Fix #12838: hook point for non-jQuery.ajax synchronous script fetch/execute in domManip. Close gh-1051. (cherry picked from commit 03db1ada2cc223edf545c5a452e55062647837fa) --- diff --git a/src/ajax.js b/src/ajax.js index 14586d18f..4478034d9 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -193,25 +193,6 @@ jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSucces }; }); -jQuery.each( [ "get", "post" ], function( i, method ) { - jQuery[ method ] = function( url, data, callback, type ) { - // shift arguments if data argument was omitted - if ( jQuery.isFunction( data ) ) { - type = type || callback; - callback = data; - data = undefined; - } - - return jQuery.ajax({ - url: url, - type: method, - dataType: type, - data: data, - success: callback - }); - }; -}); - jQuery.extend({ // Counter for holding the number of active queries @@ -695,15 +676,34 @@ jQuery.extend({ return jqXHR; }, - getScript: function( url, callback ) { - return jQuery.get( url, undefined, callback, "script" ); - }, - getJSON: function( url, data, callback ) { return jQuery.get( url, data, callback, "json" ); + }, + + getScript: function( url, callback ) { + return jQuery.get( url, undefined, callback, "script" ); } }); +jQuery.each( [ "get", "post" ], function( i, method ) { + jQuery[ method ] = function( url, data, callback, type ) { + // shift arguments if data argument was omitted + if ( jQuery.isFunction( data ) ) { + type = type || callback; + callback = data; + data = undefined; + } + + return jQuery.ajax({ + url: url, + type: method, + dataType: type, + data: data, + success: callback + }); + }; +}); + /* Handles responses to an ajax request: * - finds the right dataType (mediates between content-type and expected dataType) * - returns the corresponding response diff --git a/src/manipulation.js b/src/manipulation.js index cf0024a55..938fb0c3a 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -354,14 +354,7 @@ jQuery.fn.extend({ if ( node.src ) { // Hope ajax is available... - jQuery.ajax({ - url: node.src, - type: "GET", - dataType: "script", - async: false, - global: false, - "throws": true - }); + jQuery._evalUrl( node.src ); } else { jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) ); } @@ -798,5 +791,16 @@ jQuery.extend({ } } } + }, + + _evalUrl: function( url ) { + return jQuery.ajax({ + url: url, + type: "GET", + dataType: "text", + async: false, + global: false, + success: jQuery.globalEval + }); } }); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 2aef444ff..a1962df3b 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2150,14 +2150,18 @@ test( "html() - script exceptions bubble (#11743)", function() { expect( 2 ); raises(function() { - jQuery("#qunit-fixture").html(""); - ok( false, "error ignored" ); - }, "exception bubbled from inline script" ); - - raises(function() { - jQuery("#qunit-fixture").html(""); - ok( false, "error ignored" ); - }, "exception bubbled from remote script" ); + jQuery("#qunit-fixture").html(""); + ok( false, "Exception ignored" ); + }, "Exception bubbled from inline script" ); + + if ( jQuery.ajax ) { + raises(function() { + jQuery("#qunit-fixture").html(""); + ok( false, "Exception ignored" ); + }, "Exception thrown in remote script" ); + } else { + ok( true, "No jQuery.ajax" ); + } }); test( "checked state is cloned with clone()", function() { @@ -2197,7 +2201,7 @@ testIframeWithCallback( "buildFragment works even if document[0] is iframe's win test( "script evaluation (#11795)", function() { - expect( 11 ); + expect( 13 ); var scriptsIn, scriptsOut, fixture = jQuery("#qunit-fixture").empty(), @@ -2238,6 +2242,44 @@ test( "script evaluation (#11795)", function() { fixture.append( scriptsOut.detach() ); deepEqual( fixture.children("script").get(), scriptsOut.get(), "Scripts detached without reevaluation" ); objGlobal.ok = isOk; + + if ( jQuery.ajax ) { + Globals.register("testBar"); + jQuery("#qunit-fixture").append( "