aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2011-07-23 02:10:17 +0200
committerjaubourg <j@ubourg.net>2011-07-23 02:10:17 +0200
commite6a99fdb0ee9e0fd7552d5de8bc4acbe982e98b7 (patch)
tree9c321dfd3dc5e01837f58fef37a9102887d9a562 /src/ajax.js
parent28b470d7d38c5c3d7d478f9c3f3b743bdae57b1b (diff)
downloadjquery-e6a99fdb0ee9e0fd7552d5de8bc4acbe982e98b7.tar.gz
jquery-e6a99fdb0ee9e0fd7552d5de8bc4acbe982e98b7.zip
Fixes #9887: ajax now supports circular references into objects passed as context. Prefilter and transport developpers should add their own custom option into flatOptions when needed. Unit test added.
Diffstat (limited to 'src/ajax.js')
-rw-r--r--src/ajax.js50
1 files changed, 34 insertions, 16 deletions
diff --git a/src/ajax.js b/src/ajax.js
index 087f2febf..77659e118 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -135,6 +135,22 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions, jqX
return selection;
}
+// A special extend for ajax options
+// that takes "flat" options (not to be deep extended)
+// Fixes #9887
+function ajaxExtend( target, src ) {
+ var key, deep,
+ flatOptions = jQuery.ajaxSettings.flatOptions || {};
+ for( key in src ) {
+ if ( src[ key ] !== undefined ) {
+ ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
+ }
+ }
+ if ( deep ) {
+ jQuery.extend( true, target, deep );
+ }
+}
+
jQuery.fn.extend({
load: function( url, params, callback ) {
if ( typeof url !== "string" && _load ) {
@@ -278,23 +294,16 @@ jQuery.extend({
// Creates a full fledged settings object into target
// with both ajaxSettings and settings fields.
// If target is omitted, writes into ajaxSettings.
- ajaxSetup: function ( target, settings ) {
- if ( !settings ) {
- // Only one parameter, we extend ajaxSettings
- settings = target;
- target = jQuery.extend( true, jQuery.ajaxSettings, settings );
+ ajaxSetup: function( target, settings ) {
+ if ( settings ) {
+ // Building a settings object
+ ajaxExtend( target, jQuery.ajaxSettings );
} else {
- // target was provided, we extend into it
- jQuery.extend( true, target, jQuery.ajaxSettings, settings );
- }
- // Flatten fields we don't want deep extended
- for( var field in { context: 1, url: 1 } ) {
- if ( field in settings ) {
- target[ field ] = settings[ field ];
- } else if( field in jQuery.ajaxSettings ) {
- target[ field ] = jQuery.ajaxSettings[ field ];
- }
+ // Extending ajaxSettings
+ settings = target;
+ target = jQuery.ajaxSettings;
}
+ ajaxExtend( target, settings );
return target;
},
@@ -352,6 +361,15 @@ jQuery.extend({
// Parse text as xml
"text xml": jQuery.parseXML
+ },
+
+ // For options that shouldn't be deep extended:
+ // you can add your own custom options here if
+ // and when you create one that shouldn't be
+ // deep extended (see ajaxExtend)
+ flatOptions: {
+ context: true,
+ url: true
}
},
@@ -563,7 +581,7 @@ jQuery.extend({
completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] );
if ( fireGlobals ) {
- globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] );
+ globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
jQuery.event.trigger( "ajaxStop" );