From ac13b23bf062242f8490fe1f2d6a234a94750f79 Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Mon, 4 Apr 2016 22:42:01 +0300 Subject: [PATCH] Ajax: execute jQuery#load callback with correct context Thanks @blq (Fredrik Blomqvist) Fixes gh-3035 Close gh-3039 --- src/ajax/load.js | 2 +- test/unit/ajax.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ajax/load.js b/src/ajax/load.js index 9f1599f91..5ec3fa252 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 69eae3211..8b46c57c2 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -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( "

" ); + 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 ) { -- 2.39.5