【www.gdgbn.com--jquery】

encodeuricomponent会以utf-8编码,在gbk编码下,可不可以以gbk进行编码呢?

如果还在打encodeuricomponent主意的话,那不好意思,encodeuricomponent只会utf-8编码,并没有其他api进行其他编码;不过,别担心,看看下面:

encodeuricomponent,它是将中文、韩文等特殊字符转换成utf-8格式的url编码。

escape对0-255以外的unicode值进行编码时输出%u****格式,其它情况下escape,encodeuri,encodeuricomponent编码结果相同。

哈哈,看到希望吧?没错,就是用escape代替encodeuricomponent方法,不过必须注意:

escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,a-z

encodeuricomponent不编码字符有71个:!, ",(,),*,-,.,_,~,0-9,a-z,a-z

使用了escape之后必须对加号进行编码,否则,当内容含有加号时候会被服务端翻译为空格

$.ajax({
url: ajaxurl,
type: "post",
datatype: "html",
timeout: 20000,//超时时间设定
data:para,//参数设置
success: function(html){
}
});

 

ajax: function( s ) {
// extend the settings, but re-extend "s" so that it can be
// checked again later (in the test suite, specifically)
s = jquery.extend(true, s, jquery.extend(true, {}, jquery.ajaxsettings, s));
var jsonp, jsre = /=?(&|$)/g, status, data,
type = s.type.touppercase();
// convert data if not already a string
if ( s.data && s.processdata && typeof s.data !== "string" )
s.data = jquery.param(s.data);
........
}

 

jquery.param=function( a ) {
var s = [ ];
var encode=function(str){
str=escape(str);
str=str.replace(/+/g,"%u002b");
return str;
};
function add( key, value ){
s[ s.length ] = encode(key) + "=" + encode(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[j]) )
jquery.each( a[j], function(){
add( j, this );
});
else
add( j, jquery.isfunction(a[j]) ? a[j]() : a[j] );
// return the resulting serialization
return s.join("&").replace(/%20/g, "+");
}

本文来源:http://www.gdgbn.com/wangyezhizuo/27514/