]> source.dussan.org Git - jquery.git/commitdiff
Ajax: execute jQuery#load callback with correct context
authorOleg Gaidarenko <markelog@gmail.com>
Mon, 4 Apr 2016 19:42:01 +0000 (22:42 +0300)
committerTimmy Willison <timmywillisn@gmail.com>
Mon, 4 Apr 2016 20:24:07 +0000 (16:24 -0400)
Thanks @blq (Fredrik Blomqvist)

Fixes gh-3035
Close gh-3039

src/ajax/load.js
test/unit/ajax.js

index 7863d7cc2308a7976e73a1826c9d0d698b2ad15f..2ae4b39b9560e558afc030717da87346fe2a741a 100644 (file)
@@ -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 ] );
                        } );
                } );
        }
index deeae452d3f1bfa94520250baf2e066c5fc395d6..19c0b7b4f336f08a4ecd2230f97be7e1535f95a3 100644 (file)
@@ -1795,6 +1795,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 ) {