ASP using jquery Ajax to submit Chinese garbled solution _ Application techniques

Source: Internet
Author: User

Client page: client.html

Copy Code code as follows:

<script>
The post of jquery
$.post
(
' Server.asp ',
{
ACT: ' Dosubmit ',
Username:escape (' cloud-dwelling Community '),//coding
WebSite: ' Www.jb51.net '
},
function (data)
{
Alert (unescape (data));//decode the returned data
}
);
</script>

Server Side page: server.asp

Copy Code code as follows:

<%
response.charset= "gb2312"
Dim Username,website
If Request.Form ("Act") = "Dosubmit" Then
Username=request.form ("UserName")
WebSite =request.form ("WebSite")

' Decoding on the server side
Username=vbsunescape (UserName)//decoding

' Process data
'---Omit the data Processing Section

' Data processing after output, first with vbsescape () encoding
Response.Write Vbsescape (UserName)
End If
%>


<%
' is equivalent to escape () in JavaScript
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
' is equivalent to unescape () in JavaScript
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&AMP;CHRW (CLng ("&h" &mid (str,x+2,4))
Str=mid (STR,X+6)
Else
VBSUNESCAPE=VBSUNESCAPE&AMP;CHR (CLng ("&h" &mid (str,x+1,2))
Str=mid (str,x+3)
End If
X=instr (str, "%")
Loop
Vbsunescape=vbsunescape&str
End Function
%>

The Escape () function in JavaScript encodes the string so that it can be read on all computers.

You can use Unescape () to decode an escape () encoded string.

In fact, the ASP in these two functions are also working, incredibly many ASP site did not introduce.

Otherwise, you can decode the code by writing the function just like the above. Complex and poorly performing.

Server-side page above: Server.asp can be written as:

Unescape () and Escape () functions in ASP

Copy Code code as follows:

<%
response.charset= "gb2312"
Dim Username,website
If Request.Form ("Act") = "Dosubmit" Then
Username=request.form ("UserName")
WebSite =request.form ("WebSite")

' Decoding on the server side
Username=unescape (UserName)//decoding

' Process data
'---Omit the data Processing Section

' Data processing after output, first with vbsescape () encoding
Response.Write Escape (UserName)
End If
%>

That's a lot easier.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.