Make sure original context is maintained and not the deep extended one. Fixes #5924.
authorJohn Resig <jeresig@gmail.com>
Mon, 25 Jan 2010 06:08:24 +0000 (01:08 -0500)
committerJohn Resig <jeresig@gmail.com>
Mon, 25 Jan 2010 06:08:24 +0000 (01:08 -0500)
src/ajax.js
test/unit/ajax.js

index ee52ed8..4af502a 100644 (file)
@@ -206,7 +206,7 @@ jQuery.extend({
                var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings);
                
                var jsonp, status, data,
-                       callbackContext = s.context || s,
+                       callbackContext = origSettings && origSettings.context || s,
                        type = s.type.toUpperCase();
 
                // convert data if not already a string
index 775523e..195fa27 100644 (file)
@@ -180,6 +180,27 @@ test("Ajax events with context", function() {
        });
 });
 
+test("jQuery.ajax context modification", function() {
+       expect(1);
+
+       stop();
+
+       var obj = {}
+
+       jQuery.ajax({
+               url: url("data/name.html"),
+               context: obj,
+               beforeSend: function(){
+                       this.test = "foo";
+               },
+               complete: function() {
+                       start();
+               }
+       });
+
+       equals( obj.test, "foo", "Make sure the original object is maintained." );
+});
+
 test("jQuery.ajax() - disabled globals", function() {
        expect( 3 );
        stop();