]> 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:23:43 +0000 (16:23 -0400)
Thanks @blq (Fredrik Blomqvist)

Fixes gh-3035
Close gh-3039

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

index 9f1599f91c127eb3a40ead3bdeb7d60802aa7c21..5ec3fa252500a969b0b45767d55bf821594ff7bc 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 69eae32112a0d68cfb0cd79e768a775b26e4f84f..8b46c57c2c280994715ba34c5650b3692ffdccdb 100644 (file)
@@ -2017,6 +2017,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 ) {