Skip to content

Commit

Permalink
Ajax: execute jQuery#load callback with correct context
Browse files Browse the repository at this point in the history
Thanks @blq (Fredrik Blomqvist)

Fixes jquerygh-3035
Close jquerygh-3039
  • Loading branch information
markelog authored and timmywil committed Apr 4, 2016
1 parent c158f57 commit 5d20a3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ajax/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jQuery.fn.load = function( url, params, callback ) {
// If it fails, this function gets "jqXHR", "status", "error"
} ).always( callback && function( jqXHR, status ) {
self.each( function() {
callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] );
callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
} );
} );
}
Expand Down
19 changes: 19 additions & 0 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,25 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
}
);

QUnit.test(
"jQuery#load() - should resolve with correct context", 2,
function( assert ) {
var done = assert.async();
var ps = jQuery( "<p></p><p></p>" );
var i = 0;

ps.appendTo( "#qunit-fixture" );

ps.load( "data/ajax/method.php", function() {
assert.strictEqual( this, ps[ i++ ] );

if ( i === 2 ) {
done();
}
} );
}
);

QUnit.test(
"#11402 - jQuery.domManip() - script in comments are properly evaluated", 2,
function( assert ) {
Expand Down

0 comments on commit 5d20a3c

Please sign in to comment.