Permalink
Browse files

Ajax: execute jQuery#load callback with correct context

Thanks @blq (Fredrik Blomqvist)

Fixes gh-3035
Close gh-3039
  • Loading branch information...
1 parent c158f57 commit 5d20a3c3f10bda935c8370392a25e45719afa6b9 @markelog markelog committed with timmywil Apr 4, 2016
Showing with 20 additions and 1 deletion.
  1. +1 −1 src/ajax/load.js
  2. +19 −0 test/unit/ajax.js
View
@@ -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 ] );
} );
} );
}
View
@@ -2085,6 +2085,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 ) {
jQuery( "#qunit-fixture" ).load( "data/cleanScript.html", assert.async() );

0 comments on commit 5d20a3c

Please sign in to comment.