Skip to content

Commit 92781da

Browse files
markelogtimmywil
authored andcommitted
Ajax: execute jQuery#load callback with correct context
Thanks @blq (Fredrik Blomqvist) Fixes jquerygh-3035 Close jquerygh-3039
1 parent cfe830e commit 92781da

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
@@ -72,7 +72,7 @@ jQuery.fn.load = function( url, params, callback ) {
7272
// If it fails, this function gets "jqXHR", "status", "error"
7373
} ).always( callback && function( jqXHR, status ) {
7474
self.each( function() {
75-
callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] );
75+
callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
7676
} );
7777
} );
7878
}

test/unit/ajax.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,25 @@ QUnit.module( "ajax", {
17951795
}
17961796
);
17971797

1798+
QUnit.test(
1799+
"jQuery#load() - should resolve with correct context", 2,
1800+
function( assert ) {
1801+
var done = assert.async();
1802+
var ps = jQuery( "<p></p><p></p>" );
1803+
var i = 0;
1804+
1805+
ps.appendTo( "#qunit-fixture" );
1806+
1807+
ps.load( "data/ajax/method.php", function() {
1808+
assert.strictEqual( this, ps[ i++ ] );
1809+
1810+
if ( i === 2 ) {
1811+
done();
1812+
}
1813+
} );
1814+
}
1815+
);
1816+
17981817
QUnit.test(
17991818
"#11402 - jQuery.domManip() - script in comments are properly evaluated", 2,
18001819
function( assert ) {

0 commit comments

Comments
 (0)