Added a default quality of `*/*` for content negotiation.
[jquery.git] / src / ajax.js
index cc87133..897d424 100644 (file)
@@ -10,6 +10,7 @@ var jsc = jQuery.now(),
        rts = /([?&])_=[^&]*(&?)/,
        rurl = /^(\w+:)?\/\/([^\/?#]+)/,
        r20 = /%20/g,
+       rhash = /#.*$/,
 
        // Keep a copy of the old load method
        _load = jQuery.fn.load;
@@ -205,6 +206,7 @@ jQuery.extend({
                var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
                        jsonp, status, data, type = s.type.toUpperCase();
 
+               s.url = s.url.replace( rhash, "" );
                s.context = origSettings && origSettings.context || s;
 
                // convert data if not already a string
@@ -375,7 +377,7 @@ jQuery.extend({
 
                        // Set the Accepts header for the server, depending on the dataType
                        xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
-                               s.accepts[ s.dataType ] + ", */*" :
+                               s.accepts[ s.dataType ] + ", */*; q=0.01" :
                                s.accepts._default );
                } catch( headerError ) {}
 
@@ -540,7 +542,7 @@ jQuery.extend({
 });
 
 function buildParams( prefix, obj, traditional, add ) {
-       if ( jQuery.isArray(obj) ) {
+       if ( jQuery.isArray(obj) && obj.length ) {
                // Serialize array item.
                jQuery.each( obj, function( i, v ) {
                        if ( traditional || rbracket.test( prefix ) ) {
@@ -560,10 +562,15 @@ function buildParams( prefix, obj, traditional, add ) {
                });
                        
        } else if ( !traditional && obj != null && typeof obj === "object" ) {
+               if ( jQuery.isEmptyObject( obj ) ) {
+                       add( prefix, "" );
+
                // Serialize object item.
-               jQuery.each( obj, function( k, v ) {
-                       buildParams( prefix + "[" + k + "]", v, traditional, add );
-               });
+               } else {
+                       jQuery.each( obj, function( k, v ) {
+                               buildParams( prefix + "[" + k + "]", v, traditional, add );
+                       });
+               }
                                        
        } else {
                // Serialize scalar item.