欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Asp中使用JQuery的AJAX提交中文亂碼解決方法

 更新時間:2014年07月24日 11:33:44   投稿:junjie  
這篇文章主要介紹了Asp中使用JQuery的AJAX提交中文亂碼解決方法,使用Asp中的unescape() 和escape() 函數(shù)即可解決亂碼問題,需要的朋友可以參考下

客戶端頁:client.html

復(fù)制代碼 代碼如下:

<script>
    //jquery的post
    $.post
    (
        'server.asp',
        {
            Act:'DoSubmit',
            UserName:escape('腳本之家'),//進(jìn)行編碼
           WebSite:'www.dbjr.com.cn'
        },
        function(data)
        {
            alert(unescape(data));//對返回數(shù)據(jù)進(jìn)行解碼
        }
    );   
</script>

服務(wù)器端頁:server.asp

復(fù)制代碼 代碼如下:

< %
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 a&lt;16 Then
            s = s & "%0" & Hex(a)
        ElseIf a>=16 and a&lt;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)
        Else
            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
%>

在javascript 中escape() 函數(shù)可對字符串進(jìn)行編碼,這樣就可以在所有的計算機(jī)上讀取該字符串。

可以使用 unescape() 對 escape() 編碼的字符串進(jìn)行解碼。

其實(shí)Asp中這兩個函數(shù)也是起作用的,居然很多asp網(wǎng)站上沒有進(jìn)行介紹。

要不然只能像上面那樣寫函數(shù)進(jìn)行解碼編碼了。復(fù)雜且性能不好。

上面的服務(wù)器端頁:server.asp可以寫成:

Asp中的unescape() 與 escape() 函數(shù)

復(fù)制代碼 代碼如下:

< %
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
%>

這樣就簡單多了。

相關(guān)文章

最新評論