aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Gaidarenko <markelog@gmail.com>2016-04-04 22:42:01 +0300
committerTimmy Willison <timmywillisn@gmail.com>2016-04-04 16:24:07 -0400
commit92781dad2100a89a46d20e0b73268907bfabe578 (patch)
tree38e7e5589c57f99d4d80477ecaedacbebc51e8ff
parentcfe830eefdd7f1e7cb87e9841d1d732d6d99ffae (diff)
downloadjquery-92781dad2100a89a46d20e0b73268907bfabe578.tar.gz
jquery-92781dad2100a89a46d20e0b73268907bfabe578.zip
Ajax: execute jQuery#load callback with correct context
Thanks @blq (Fredrik Blomqvist) Fixes gh-3035 Close gh-3039
-rw-r--r--src/ajax/load.js2
-rw-r--r--test/unit/ajax.js19
2 files changed, 20 insertions, 1 deletions
diff --git a/src/ajax/load.js b/src/ajax/load.js
index 7863d7cc2..2ae4b39b9 100644
--- a/src/ajax/load.js
+++ b/src/ajax/load.js
@@ -72,7 +72,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 ] );
} );
} );
}
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index deeae452d..19c0b7b4f 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1796,6 +1796,25 @@ QUnit.module( "ajax", {
);
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() );