Skip to content

Commit

Permalink
jquery ajax: Closes #2567, additional setting for $.ajax called 'data…
Browse files Browse the repository at this point in the history
…Filter'. It's an optional function that receives the ajax response, and returns the sanitized version.
  • Loading branch information
flesler committed May 16, 2008
1 parent 2c2a625 commit afc2ebd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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" )
Expand Down

0 comments on commit afc2ebd

Please sign in to comment.