Ticket #2726: param.diff
File param.diff, 1.7 KB (added by , 14 years ago) |
---|
-
src/ajax.js
479 479 param: function( a ) { 480 480 var s = []; 481 481 482 function add( key, value ){ 483 s[s.length] = key + "=" + encodeURIComponent( value ); 484 }; 485 482 486 // If an array was passed in, assume that it is an array 483 487 // of form elements 484 488 if ( a.constructor == Array || a.jquery ) 485 489 // Serialize the form elements 486 490 jQuery.each( a, function(){ 487 s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ));491 add( encodeURIComponent(this.name), this.value ); 488 492 }); 489 493 490 494 // Otherwise, assume that it's an object of key/value pairs 491 495 else 492 496 // Serialize the key/values 493 for ( var j in a ) 494 // If the value is an array then the key names need to be repeated 495 if ( a[j] && a[j].constructor == Array ) 496 jQuery.each( a[j], function(){ 497 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); 497 for ( var j in a ){ 498 var obj = a[j]; 499 500 // Encode it, but don't encode the squared brackets afterwards 501 j = encodeURIComponent(j); 502 503 // If the value is an array or a map, generate name[key]=value 504 if ( obj && typeof obj == 'object' ) 505 jQuery.each( obj, function( key, v ){ 506 var name = j; 507 // Don't break name[]=v1&name[]=v2 ... 508 if( j.indexOf('[]') == -1 ) 509 name += '['+k+']'; 510 add( name , v ); 498 511 }); 499 512 else 500 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) ); 513 add( j, jQuery.isFunction(obj) ? obj() : obj ); 514 } 501 515 502 516 // Return the resulting serialization 503 517 return s.join("&").replace(/%20/g, "+");