aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriel Flesler <aflesler@gmail.com>2008-05-16 16:39:27 +0000
committerAriel Flesler <aflesler@gmail.com>2008-05-16 16:39:27 +0000
commitafc2ebde1425722f4e2df14919c0df0ff7d2ff0c (patch)
treeb68366586c2c961db5a83039f8785de4605532aa
parent2c2a6253e3744983741882ca4565a20b4b0b3f42 (diff)
downloadjquery-afc2ebde1425722f4e2df14919c0df0ff7d2ff0c.tar.gz
jquery-afc2ebde1425722f4e2df14919c0df0ff7d2ff0c.zip
jquery ajax: Closes #2567, additional setting for $.ajax called 'dataFilter'. It's an optional function that receives the ajax response, and returns the sanitized version.
-rw-r--r--src/ajax.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/ajax.js b/src/ajax.js
index d1a2ec23c..a0c80afe6 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -336,7 +336,7 @@ jQuery.extend({
// Watch for, and catch, XML document parse errors
try {
// process the data (runs the xml through httpData regardless of callback)
- data = jQuery.httpData( xhr, s.dataType );
+ data = jQuery.httpData( xhr, s.dataType, s.dataFilter );
} catch(e) {
status = "parsererror";
}
@@ -460,13 +460,17 @@ jQuery.extend({
return false;
},
- httpData: function( xhr, type ) {
+ httpData: function( xhr, type, filter ) {
var ct = xhr.getResponseHeader("content-type"),
xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
data = xml ? xhr.responseXML : xhr.responseText;
if ( xml && data.documentElement.tagName == "parsererror" )
throw "parsererror";
+
+ // Allow a pre-filtering function to sanitize the response
+ if( filter )
+ data = filter( data, type );
// If the type is "script", eval it in global context
if ( type == "script" )