From 5d20a3c3f10bda935c8370392a25e45719afa6b9 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 82f0cf308..aa6e1cfab 100644 --- a/src/ajax/load.js +++ b/src/ajax/load.js @@ -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 ] ); } ); } ); } diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 949bf5f20..297f051d9 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2084,6 +2084,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