Made some code tweaks related to running jQuery through JSLint (thanks to Lorin Larso...
[jquery.git] / src / ajax.js
index ee52ed8..e17dfa8 100644 (file)
@@ -6,15 +6,15 @@ var jsc = now(),
        rquery = /\?/,
        rts = /(\?|&)_=.*?(&|$)/,
        rurl = /^(\w+:)?\/\/([^\/?#]+)/,
-       r20 = /%20/g;
+       r20 = /%20/g,
 
-jQuery.fn.extend({
-       // Keep a copy of the old load
-       _load: jQuery.fn.load,
+       // Keep a copy of the old load method
+       _load = jQuery.fn.load;
 
+jQuery.fn.extend({
        load: function( url, params, callback ) {
-               if ( typeof url !== "string" ) {
-                       return this._load( url );
+               if ( typeof url !== "string" && _load ) {
+                       return _load.apply( this, arguments );
 
                // Don't do a request if no elements are being requested
                } else if ( !this.length ) {
@@ -206,7 +206,7 @@ jQuery.extend({
                var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings);
                
                var jsonp, status, data,
-                       callbackContext = s.context || s,
+                       callbackContext = origSettings && origSettings.context || s,
                        type = s.type.toUpperCase();
 
                // convert data if not already a string
@@ -278,8 +278,10 @@ jQuery.extend({
                        s.url += (rquery.test(s.url) ? "&" : "?") + s.data;
                }
 
+               jQuery.active++;
+
                // Watch for a new set of requests
-               if ( s.global && ! jQuery.active++ ) {
+               if ( s.global && jQuery.active === 1 ) {
                        jQuery.event.trigger( "ajaxStart" );
                }
 
@@ -386,7 +388,7 @@ jQuery.extend({
                }
 
                if ( s.global ) {
-                       trigger("ajaxSend", [xhr, s]);
+                       contextTrigger("ajaxSend", [xhr, s]);
                }
 
                // Wait for a response to come back
@@ -417,13 +419,16 @@ jQuery.extend({
                                                        "notmodified" :
                                                        "success";
 
+                               var errMsg;
+
                                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, s );
-                                       } catch(e) {
+                                       } catch(err) {
                                                status = "parsererror";
+                                               errMsg = err;
                                        }
                                }
 
@@ -434,7 +439,7 @@ jQuery.extend({
                                                success();
                                        }
                                } else {
-                                       jQuery.handleError(s, xhr, status);
+                                       jQuery.handleError(s, xhr, status, errMsg);
                                }
 
                                // Fire the complete handlers
@@ -496,7 +501,7 @@ jQuery.extend({
 
                        // Fire the global callback
                        if ( s.global ) {
-                               trigger( "ajaxSuccess", [xhr, s] );
+                               contextTrigger( "ajaxSuccess", [xhr, s] );
                        }
                }
 
@@ -508,7 +513,7 @@ jQuery.extend({
 
                        // The request was completed
                        if ( s.global ) {
-                               trigger( "ajaxComplete", [xhr, s] );
+                               contextTrigger( "ajaxComplete", [xhr, s] );
                        }
 
                        // Handle the global AJAX counter
@@ -517,7 +522,7 @@ jQuery.extend({
                        }
                }
                
-               function trigger(type, args) {
+               function contextTrigger(type, args) {
                        (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args);
                }
 
@@ -632,7 +637,7 @@ jQuery.extend({
                        if ( jQuery.isArray(obj) ) {
                                // Serialize array item.
                                jQuery.each( obj, function( i, v ) {
-                                       if ( traditional ) {
+                                       if ( traditional || /\[\]$/.test( prefix ) ) {
                                                // Treat each array item as a scalar.
                                                add( prefix, v );
                                        } else {