Skip to content

Commit ac13b23

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 1f4817d commit ac13b23

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
@@ -2017,6 +2017,25 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
20172017
}
20182018
);
20192019

2020+
QUnit.test(
2021+
"jQuery#load() - should resolve with correct context", 2,
2022+
function( assert ) {
2023+
var done = assert.async();
2024+
var ps = jQuery( "<p></p><p></p>" );
2025+
var i = 0;
2026+
2027+
ps.appendTo( "#qunit-fixture" );
2028+
2029+
ps.load( "data/ajax/method.php", function() {
2030+
assert.strictEqual( this, ps[ i++ ] );
2031+
2032+
if ( i === 2 ) {
2033+
done();
2034+
}
2035+
} );
2036+
}
2037+
);
2038+
20202039
QUnit.test(
20212040
"#11402 - jQuery.domManip() - script in comments are properly evaluated", 2,
20222041
function( assert ) {

0 commit comments

Comments
 (0)