1. [代码][ASP/Basic]代码
‘在客户端使用javascript的escape()方法对数据进行编码,在服务器端使用对等的VbsUnEscape()对数据进行解码,同样在服务器端使用VbsEscape()对数据进行编码,在客户端使用unescape()对数据进行解码
‘与javascript中的escape()等效
Function VbsEscape(str)
dim i,s,c,a
s=""
For i=1 to Len(str)
c=Mid(str,i,1)
a=ASCW(c)
If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
s = s & c
ElseIf InStr("@*_+-./",c)>0 Then
s = s & c
ElseIf a>0 and a<16 Then
s = s & "%0" & Hex(a)
ElseIf a>=16 and a<256 Then
s = s & "%" & Hex(a)
Else
s = s & "%u" & Hex(a)
End If
Next
VbsEscape=s
End Function
‘与javascript中的unescape()等效
Function VbsUnEscape(str)
Dim x
x=InStr(str,"%")
Do While x>0
VbsUnEscape=VbsUnEscape&Mid(str,1,x-1)
If LCase(Mid(str,x+1,1))="u" Then
VbsUnEscape=VbsUnEscape&ChrW(CLng("&H"&Mid(str,x+2,4)))
str=Mid(str,x+6)背景音乐
Elsehttp://www.huiyi8.com/bgm/ppt/?
VbsUnEscape=VbsUnEscape&Chr(CLng("&H"&Mid(str,x+1,2)))
str=Mid(str,x+3)
End If
x=InStr(str,"%")
Loop
VbsUnEscape=VbsUnEscape&str
End Function
2. [代码][JavaScript]代码
//jQuery客户端代码演示
$.post
(
‘server.asp‘,
{
Act:‘DoSubmit‘,
UserName:escape(‘西楼冷月‘),//进行编码
WebSite:‘www.chinacms.org‘
},
function(data)
{
alert(unescape(data));//对返回数据进行解码
}
);
3. [代码][ASP/Basic]代码
‘服务器端代码演示
Response.Charset="gb2312"
Dim UserName,WebSite
If Request.Form("Act")="DoSubmit" Then
UserName=Request.Form("UserName")
WebSite =Request.Form("WebSite")
‘在服务器端解码
UserName=VbsUnEscape(UserName)//解码
‘处理数据
‘---省略数据处理部分
‘数据处理后输出,先用VbsEscape()编码
‘by www.chinacms.org
Response.Write VbsEscape(UserName)
End If
asp+jQuery解决中文乱码