Skip to content

Commit 5d20a3c

Browse files
markelogtimmywil
authored andcommitted
Ajax: execute jQuery#load callback with correct context
Thanks @blq (Fredrik Blomqvist) Fixes gh-3035 Close gh-3039
1 parent c158f57 commit 5d20a3c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ajax/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jQuery.fn.load = function( url, params, callback ) {
6262
// If it fails, this function gets "jqXHR", "status", "error"
6363
} ).always( callback && function( jqXHR, status ) {
6464
self.each( function() {
65-
callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] );
65+
callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
6666
} );
6767
} );
6868
}

test/unit/ajax.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,25 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
20842084
}
20852085
);
20862086

2087+
QUnit.test(
2088+
"jQuery#load() - should resolve with correct context", 2,
2089+
function( assert ) {
2090+
var done = assert.async();
2091+
var ps = jQuery( "<p></p><p></p>" );
2092+
var i = 0;
2093+
2094+
ps.appendTo( "#qunit-fixture" );
2095+
2096+
ps.load( "data/ajax/method.php", function() {
2097+
assert.strictEqual( this, ps[ i++ ] );
2098+
2099+
if ( i === 2 ) {
2100+
done();
2101+
}
2102+
} );
2103+
}
2104+
);
2105+
20872106
QUnit.test(
20882107
"#11402 - jQuery.domManip() - script in comments are properly evaluated", 2,
20892108
function( assert ) {

0 commit comments

Comments
 (0)