wy_sc 发表于 2013-1-29 11:41:08

jQuery ajax乱码问题

加载完jQuery之后在js中重写params函数
 
 
//二次编码,后台使用URLDecoder.decode()方法解码汉字
jQuery.param=function( a ) {
 var s = [ ];
 function add( key, value ){
  s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(encodeURIComponent(value));
 };
 // If an array was passed in, assume that it is an array
 // of form elements
 if ( jQuery.isArray(a) || a.jquery )
  // Serialize the form elements
  jQuery.each( a, function(){
   add( this.name, this.value );
  });
 // Otherwise, assume that it's an object of key/value pairs
 else
  // Serialize the key/values
  for ( var j in a )
   // If the value is an array then the key names need to be repeated
   if ( jQuery.isArray(a) )
    jQuery.each( a, function(){
     add( j, this );
    });
   else
    add( j, jQuery.isFunction(a) ? a() : a );
 // Return the resulting serialization
 return s.join("&").replace(/%20/g, "+");
}
页: [1]
查看完整版本: jQuery ajax乱码问题