Commit 0100becc authored by Richard Gibson's avatar Richard Gibson

Fix #12838: hook point for non-jQuery.ajax synchronous script fetch/execute in...

Fix #12838: hook point for non-jQuery.ajax synchronous script fetch/execute in domManip. Close gh-1051.
(cherry picked from commit 03db1ada)
parent e572eed2
...@@ -193,25 +193,6 @@ jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSucces ...@@ -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({ jQuery.extend({
// Counter for holding the number of active queries // Counter for holding the number of active queries
...@@ -695,13 +676,32 @@ jQuery.extend({ ...@@ -695,13 +676,32 @@ jQuery.extend({
return jqXHR; return jqXHR;
}, },
getJSON: function( url, data, callback ) {
return jQuery.get( url, data, callback, "json" );
},
getScript: function( url, callback ) { getScript: function( url, callback ) {
return jQuery.get( url, undefined, callback, "script" ); return jQuery.get( url, undefined, callback, "script" );
}, }
});
getJSON: function( url, data, callback ) { jQuery.each( [ "get", "post" ], function( i, method ) {
return jQuery.get( url, data, callback, "json" ); 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: /* Handles responses to an ajax request:
......
...@@ -354,14 +354,7 @@ jQuery.fn.extend({ ...@@ -354,14 +354,7 @@ jQuery.fn.extend({
if ( node.src ) { if ( node.src ) {
// Hope ajax is available... // Hope ajax is available...
jQuery.ajax({ jQuery._evalUrl( node.src );
url: node.src,
type: "GET",
dataType: "script",
async: false,
global: false,
"throws": true
});
} else { } else {
jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) ); jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) );
} }
...@@ -798,5 +791,16 @@ jQuery.extend({ ...@@ -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
});
} }
}); });
...@@ -2150,14 +2150,18 @@ test( "html() - script exceptions bubble (#11743)", function() { ...@@ -2150,14 +2150,18 @@ test( "html() - script exceptions bubble (#11743)", function() {
expect( 2 ); expect( 2 );
raises(function() { raises(function() {
jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'error not thrown' );</script>"); jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>");
ok( false, "error ignored" ); ok( false, "Exception ignored" );
}, "exception bubbled from inline script" ); }, "Exception bubbled from inline script" );
if ( jQuery.ajax ) {
raises(function() { raises(function() {
jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>"); jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>");
ok( false, "error ignored" ); ok( false, "Exception ignored" );
}, "exception bubbled from remote script" ); }, "Exception thrown in remote script" );
} else {
ok( true, "No jQuery.ajax" );
}
}); });
test( "checked state is cloned with clone()", function() { test( "checked state is cloned with clone()", function() {
...@@ -2197,7 +2201,7 @@ testIframeWithCallback( "buildFragment works even if document[0] is iframe's win ...@@ -2197,7 +2201,7 @@ testIframeWithCallback( "buildFragment works even if document[0] is iframe's win
test( "script evaluation (#11795)", function() { test( "script evaluation (#11795)", function() {
expect( 11 ); expect( 13 );
var scriptsIn, scriptsOut, var scriptsIn, scriptsOut,
fixture = jQuery("#qunit-fixture").empty(), fixture = jQuery("#qunit-fixture").empty(),
...@@ -2238,6 +2242,44 @@ test( "script evaluation (#11795)", function() { ...@@ -2238,6 +2242,44 @@ test( "script evaluation (#11795)", function() {
fixture.append( scriptsOut.detach() ); fixture.append( scriptsOut.detach() );
deepEqual( fixture.children("script").get(), scriptsOut.get(), "Scripts detached without reevaluation" ); deepEqual( fixture.children("script").get(), scriptsOut.get(), "Scripts detached without reevaluation" );
objGlobal.ok = isOk; objGlobal.ok = isOk;
if ( jQuery.ajax ) {
Globals.register("testBar");
jQuery("#qunit-fixture").append( "<script src='" + url("data/test.js") + "'/>" );
strictEqual( window["testBar"], "bar", "Global script evaluation" );
} else {
ok( true, "No jQuery.ajax" );
ok( true, "No jQuery.ajax" );
}
});
test( "jQuery._evalUrl (#12838)", function() {
expect( 5 );
var message, expectedArgument,
ajax = jQuery.ajax,
evalUrl = jQuery._evalUrl;
message = "jQuery.ajax implementation";
expectedArgument = 1;
jQuery.ajax = function( input ) {
equal( ( input.url || input ).slice( -1 ), expectedArgument, message );
expectedArgument++;
};
jQuery("#qunit-fixture").append("<script src='1'/><script src='2'/>");
equal( expectedArgument, 3, "synchronous execution" );
message = "custom implementation";
expectedArgument = 3;
jQuery._evalUrl = jQuery.ajax;
jQuery.ajax = function( options ) {
strictEqual( options, {}, "Unexpected call to jQuery.ajax" );
};
jQuery("#qunit-fixture").append("<script src='3'/><script src='4'/>");
jQuery.ajax = ajax;
jQuery._evalUrl = evalUrl;
}); });
test( "wrapping scripts (#10470)", function() { test( "wrapping scripts (#10470)", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment