Ajax: execute jQuery#load callback with correct context

Thanks @blq (Fredrik Blomqvist)

Fixes gh-3035
Close gh-3039
This commit is contained in:
Oleg Gaidarenko 2016-04-04 22:42:01 +03:00 committed by Timmy Willison
parent c158f5761a
commit 5d20a3c3f1
2 changed files with 20 additions and 1 deletions

View File

@ -62,7 +62,7 @@ jQuery.fn.load = function( url, params, callback ) {
// If it fails, this function gets "jqXHR", "status", "error" // If it fails, this function gets "jqXHR", "status", "error"
} ).always( callback && function( jqXHR, status ) { } ).always( callback && function( jqXHR, status ) {
self.each( function() { self.each( function() {
callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] ); callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
} ); } );
} ); } );
} }

View File

@ -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( QUnit.test(
"#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2,
function( assert ) { function( assert ) {