在Ajax发送url参数传递时,一定会传递含有中文的参数或URL地址,
在有些传递页面使用GB2312,而javascript中encodeURI和encodeURIComponent函数编码的都是UTF8
var url = "我";
codeUrl = gb2312Encode(url);
alert(codeUrl);
function Hex(n){
c = n;
execScript("c = Hex(c)", "vbscript");
return c;
}
function Asc(s){
c = s;
execScript("c = Asc(c)", "vbscript");
return c;
}
function gb2312Encode(str){
var string = "";
c = s = "";
var high = "";
var low = "";
for(var i = 0; i < str.length; i++) { c = Asc(str.charAt(i)); if(Math.abs(c) < 0xFF) string += str.charAt(i); else { if(c < 0) c += 0x10000; high = ((c & 0xFF00) >> 8) & 0x00FF;
low = c & 0xFF;
string += "%" + Hex(high) + "%" + Hex(low);
}
}
return string;
}
发表回复