jquery ajax: misc optimization for $.fn.load().
[jquery.git] / src / ajax.js
index 853bcbb..bda79b5 100644 (file)
@@ -12,8 +12,6 @@ jQuery.fn.extend({
                        url = url.slice(0, off);
                }
 
-               callback = callback || function(){};
-
                // Default to a GET request
                var type = "GET";
 
@@ -56,7 +54,8 @@ jQuery.fn.extend({
                                                // If not, just inject the full result
                                                res.responseText );
 
-                               self.each( callback, [res.responseText, status, res] );
+                               if( callback )
+                                       self.each( callback, [res.responseText, status, res] );
                        }
                });
                return this;
@@ -97,6 +96,7 @@ jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp
 var jsc = now();
 
 jQuery.extend({
+  
        get: function( url, data, callback, type ) {
                // shift arguments if data argument was ommited
                if ( jQuery.isFunction( data ) ) {
@@ -151,6 +151,12 @@ jQuery.extend({
                data: null,
                username: null,
                password: null,
+               // Create the request object; Microsoft failed to properly
+               // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
+               // This function can be overriden by calling jQuery.ajaxSetup
+               xhr:function(){
+                       return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
+               },
                accepts: {
                        xml: "application/xml, text/xml",
                        html: "text/html",
@@ -273,9 +279,8 @@ jQuery.extend({
 
                var requestDone = false;
 
-               // Create the request object; Microsoft failed to properly
-               // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
-               var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
+               // Create the request object
+               var xhr = s.xhr();
 
                // Open the socket
                // Passing null username, generates a login popup on Opera (#2865)
@@ -474,14 +479,18 @@ jQuery.extend({
                if( s && s.dataFilter )
                        data = s.dataFilter( data, type );
 
-               // If the type is "script", eval it in global context
-               if ( type == "script" )
-                       jQuery.globalEval( data );
+               // The filter can actually parse the response
+               if( typeof data == 'string' ){
 
-               // Get the JavaScript object, if JSON is used.
-               if ( type == "json" )
-                       data = eval("(" + data + ")");
+                       // If the type is "script", eval it in global context
+                       if ( type == "script" )
+                               jQuery.globalEval( data );
 
+                       // Get the JavaScript object, if JSON is used.
+                       if ( type == "json" )
+                               data = eval("(" + data + ")");
+               }
+               
                return data;
        },