客戶端頁:client.html
復制代碼 代碼如下:
script>
//jquery的post
$.post
(
'server.asp',
{
Act:'DoSubmit',
UserName:escape('腳本之家'),//進行編碼
WebSite:'www.jb51.net'
},
function(data)
{
alert(unescape(data));//對返回數(shù)據(jù)進行解碼
}
);
/script>
服務(wù)器端頁:server.asp
復制代碼 代碼如下:
%
Response.Charset="gb2312"
Dim UserName,WebSite
If Request.Form("Act")="DoSubmit" Then
UserName=Request.Form("UserName")
WebSite =Request.Form("WebSite")
'在服務(wù)器端解碼
UserName=VbsUnEscape(UserName)//解碼
'處理數(shù)據(jù)
'---省略數(shù)據(jù)處理部分
'數(shù)據(jù)處理后輸出,先用VbsEscape()編碼
Response.Write VbsEscape(UserName)
End If
%>
%
'與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 alt;16 Then
s = s "%0" Hex(a)
ElseIf a>=16 and alt;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=VbsUnEscapeMid(str,1,x-1)
If LCase(Mid(str,x+1,1))="u" Then
VbsUnEscape=VbsUnEscapeChrW(CLng("H"Mid(str,x+2,4)))
str=Mid(str,x+6)
Else
VbsUnEscape=VbsUnEscapeChr(CLng("H"Mid(str,x+1,2)))
str=Mid(str,x+3)
End If
x=InStr(str,"%")
Loop
VbsUnEscape=VbsUnEscapestr
End Function
%>
在javascript 中escape() 函數(shù)可對字符串進行編碼,這樣就可以在所有的計算機上讀取該字符串。
可以使用 unescape() 對 escape() 編碼的字符串進行解碼。
其實Asp中這兩個函數(shù)也是起作用的,居然很多asp網(wǎng)站上沒有進行介紹。
要不然只能像上面那樣寫函數(shù)進行解碼編碼了。復雜且性能不好。
上面的服務(wù)器端頁:server.asp可以寫成:
Asp中的unescape() 與 escape() 函數(shù)
復制代碼 代碼如下:
%
Response.Charset="gb2312"
Dim UserName,WebSite
If Request.Form("Act")="DoSubmit" Then
UserName=Request.Form("UserName")
WebSite =Request.Form("WebSite")
'在服務(wù)器端解碼
UserName=UnEscape(UserName)//解碼
'處理數(shù)據(jù)
'---省略數(shù)據(jù)處理部分
'數(shù)據(jù)處理后輸出,先用VbsEscape()編碼
Response.Write Escape(UserName)
End If
%>
這樣就簡單多了。
您可能感興趣的文章:- JQuery中Ajax的Post提交在IE下中文亂碼的解決方法
- jquery.ajax的url中傳遞中文亂碼問題的解決方法
- jquery的ajax()函數(shù)傳值中文亂碼解決方法介紹
- JQuery ajax 返回json時出現(xiàn)中文亂碼該如何解決
- 如何解決JQuery ajaxSubmit提交中文亂碼
- JQuery AJAX 中文亂碼問題解決
- JQuery AJAX提交中文亂碼的解決方案
- jQuery ajax方法傳遞中文時出現(xiàn)中文亂碼的解決方法