Commit 155ecf42 authored by John Resig's avatar John Resig

Make sure regular settings object is set as context for all Ajax requests, if...

Make sure regular settings object is set as context for all Ajax requests, if none is specified. Fixes #5838.
parent 6618ff0b
...@@ -530,7 +530,7 @@ jQuery.extend({ ...@@ -530,7 +530,7 @@ jQuery.extend({
handleError: function( s, xhr, status, e ) { handleError: function( s, xhr, status, e ) {
// If a local callback was specified, fire it // If a local callback was specified, fire it
if ( s.error ) { if ( s.error ) {
s.error.call( s.context || window, xhr, status, e ); s.error.call( s.context || s, xhr, status, e );
} }
// Fire the global callback // Fire the global callback
......
...@@ -95,7 +95,7 @@ test("jQuery.ajax() - abort", function() { ...@@ -95,7 +95,7 @@ test("jQuery.ajax() - abort", function() {
}); });
test("Ajax events with context", function() { test("Ajax events with context", function() {
expect(6); expect(14);
stop(); stop();
var context = document.createElement("div"); var context = document.createElement("div");
...@@ -104,8 +104,16 @@ test("Ajax events with context", function() { ...@@ -104,8 +104,16 @@ test("Ajax events with context", function() {
equals( this, context, e.type ); equals( this, context, e.type );
} }
function callback(){ function callback(msg){
equals( this, context, "context is preserved on callback" ); return function(){
equals( this, context, "context is preserved on callback " + msg );
};
}
function nocallback(msg){
return function(){
equals( typeof this.url, "string", "context is settings on callback " + msg );
};
} }
jQuery('#foo').add(context) jQuery('#foo').add(context)
...@@ -116,20 +124,36 @@ test("Ajax events with context", function() { ...@@ -116,20 +124,36 @@ test("Ajax events with context", function() {
jQuery.ajax({ jQuery.ajax({
url: url("data/name.html"), url: url("data/name.html"),
beforeSend: callback, beforeSend: callback("beforeSend"),
success: callback, success: callback("success"),
error: callback, error: callback("error"),
complete:function(){ complete:function(){
callback.call(this); callback("complete").call(this);
setTimeout(proceed, 300);
jQuery.ajax({
url: url("data/404.html"),
context: context,
beforeSend: callback("beforeSend"),
error: callback("error"),
complete: function(){
callback("complete").call(this);
jQuery('#foo').add(context).unbind();
jQuery.ajax({
url: url("data/404.html"),
beforeSend: nocallback("beforeSend"),
error: nocallback("error"),
complete: function(){
nocallback("complete").call(this);
start();
}
});
}
});
}, },
context:context context:context
}); });
function proceed(){
jQuery('#foo').add(context).unbind();
start();
}
}); });
test("jQuery.ajax() - disabled globals", function() { test("jQuery.ajax() - disabled globals", 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