From 5a721cf31b142365954a2d71e860534da4536b16 Mon Sep 17 00:00:00 2001
From: jaubourg <j@ubourg.net>
Date: Tue, 11 Jan 2011 20:02:33 +0100
Subject: [PATCH] Fixes 4825. jQuery.fn.load: use the jXHR's Promise interface
 to get the actual response in case ajaxSettings contains a
 dataFilter. Unit test added.

---
 src/ajax.js       |   18 +++++++++++++-----
 test/unit/ajax.js |   12 ++++++++++++
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/ajax.js b/src/ajax.js
index d570fcc..82c499b 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -61,26 +61,34 @@ jQuery.fn.extend({
 			type: type,
 			dataType: "html",
 			data: params,
-			complete: function( res, status ) {
+			// Complete callback (responseText is used internally)
+			complete: function( jXHR, status, responseText ) {
+				// Store the response as specified by the jXHR object
+				responseText = jXHR.responseText;
 				// If successful, inject the HTML into all the matched elements
-				if ( status === "success" || status === "notmodified" ) {
+				if ( jXHR.isResolved() ) {
+					// #4825: Get the actual response in case
+					// a dataFilter is present in ajaxSettings
+					jXHR.done(function( r ) {
+						responseText = r;
+					});
 					// See if a selector was specified
 					self.html( selector ?
 						// Create a dummy div to hold the results
 						jQuery("<div>")
 							// inject the contents of the document in, removing the scripts
 							// to avoid any 'Permission Denied' errors in IE
-							.append(res.responseText.replace(rscript, ""))
+							.append(responseText.replace(rscript, ""))
 
 							// Locate the specified elements
 							.find(selector) :
 
 						// If not, just inject the full result
-						res.responseText );
+						responseText );
 				}
 
 				if ( callback ) {
-					self.each( callback, [res.responseText, status, res] );
+					self.each( callback, [responseText, status, jXHR] );
 				}
 			}
 		});
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 9f46c41..1b55402 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1025,6 +1025,18 @@ test("load(String, Function) - check file with only a script tag", function() {
 	});
 });
 
+test("load(String, Function) - dataFilter in ajaxSettings", function() {
+	expect(2);
+	stop();
+	jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } });
+	var div = jQuery("<div/>").load(url("data/name.html"), function(responseText) {
+		strictEqual( div.html(), "Hello World" , "Test div was filled with filtered data" );
+		strictEqual( responseText, "Hello World" , "Test callback receives filtered data" );
+		jQuery.ajaxSetup({ dataFilter: 0 });
+		start();
+	});
+});
+
 test("load(String, Object, Function)", function() {
 	expect(2);
 	stop();
-- 
1.7.10.4