Skip to content

Commit afc2ebd

Browse files
committed
jquery ajax: Closes jquery#2567, additional setting for $.ajax called 'dataFilter'. It's an optional function that receives the ajax response, and returns the sanitized version.
1 parent 2c2a625 commit afc2ebd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ajax.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ jQuery.extend({
336336
// Watch for, and catch, XML document parse errors
337337
try {
338338
// process the data (runs the xml through httpData regardless of callback)
339-
data = jQuery.httpData( xhr, s.dataType );
339+
data = jQuery.httpData( xhr, s.dataType, s.dataFilter );
340340
} catch(e) {
341341
status = "parsererror";
342342
}
@@ -460,13 +460,17 @@ jQuery.extend({
460460
return false;
461461
},
462462

463-
httpData: function( xhr, type ) {
463+
httpData: function( xhr, type, filter ) {
464464
var ct = xhr.getResponseHeader("content-type"),
465465
xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
466466
data = xml ? xhr.responseXML : xhr.responseText;
467467

468468
if ( xml && data.documentElement.tagName == "parsererror" )
469469
throw "parsererror";
470+
471+
// Allow a pre-filtering function to sanitize the response
472+
if( filter )
473+
data = filter( data, type );
470474

471475
// If the type is "script", eval it in global context
472476
if ( type == "script" )

0 commit comments

Comments
 (0)