原文:http://www.wsria.cn/archives/611
1、jQuery 1.2.6 乱码解决办法
打开1.2.6版本的源文件
找到第2911、2921、2924行,分别修改对应参数值的地方包裹一层encodeURIComponent即可,修改后的结果如下:
param: function( a ) {
var s = [];
// If an array was passed in, assume that it is an array
// of form elements
if ( a.constructor == Array || a.jquery )
// Serialize the form elements
jQuery.each( a, function(){
s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent(encodeURIComponent( 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 ( a[j] && a[j].constructor == Array )
jQuery.each( a[j], function(){
s.push( encodeURIComponent(j) + "=" + encodeURIComponent(encodeURIComponent( this )) );
});
else
s.push( encodeURIComponent(j) + "=" + encodeURIComponent(encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] )) );
// Return the resulting serialization
return s.join("&").replace(/%20/g, "+");
}
下载:jquery-encode-gbk.1.2.6.js
下载:jquery-encode-gbk.pack.1.2.6.js
2、jQuery 1.3.2 乱码解决办法
1.3.2的就不用这么麻烦了,因为这个版本简化了param方法的结构,只需要修改一行代码即可,因为只有一个地方转码了
找到第3737行,同样包裹一层encodeURIComponent,结果如下:
param: function( a ) {
var s = [ ];
function add( key, value ){
s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(encodeURIComponent(value));
};
下载:jquery-encode-gbk-1.3.2.js
下载:jquery-encode-gbk-.pack.1.3.2.js