jquery ajax: Closes #1516. load() can get a string of data (not only a hash) and...
[jquery.git] / src / ajax.js
index d1a2ec2..eb81e4c 100644 (file)
@@ -26,7 +26,7 @@ jQuery.fn.extend({
                                params = null;
 
                        // Otherwise, build a param string
-                       } else {
+                       } else if( typeof params == 'object' ) {
                                params = jQuery.param( params );
                                type = "POST";
                        }
@@ -327,16 +327,16 @@ jQuery.extend({
                                        ival = null;
                                }
 
-                               status = isTimeout == "timeout" && "timeout" ||
-                                       !jQuery.httpSuccess( xhr ) && "error" ||
-                                       s.ifModified && jQuery.httpNotModified( xhr, s.url ) && "notmodified" ||
+                               status = isTimeout == "timeout" ? "timeout" :
+                                       !jQuery.httpSuccess( xhr ) ? "error" :
+                                       s.ifModified && jQuery.httpNotModified( xhr, s.url ) ? "notmodified" :
                                        "success";
 
                                if ( status == "success" ) {
                                        // 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" )