ASP encoding process using Chinese ajax to pass parameters

background

asp 0.9 Beta is the first edition, in 1996 ASP1.0 since birth, so far more than 20 set. Although the asp in Windows2000 IIS 5.0 is included with the service after the release of ASP 3.0 as if no updated, but simply because of its start, natural asp + access zero configuration, zero a few years in the fire just like the small micro-channel program. Although the passage of time, which is still in the domestic market as well as small-scale users.

According to the Ministry announced that by the end of 2018, the number of SMEs in China has exceeded 30 million, the number of individual businesses over 70 million. SME information generally faced with a shortage of funds, lack of information personnel and other issues, in order to reduce costs, and therefore business website generally outsourced to other small-scale network company production, maintenance, network companies are generally sets of points, imitation station. Operating systems typically use Windows, web program to build on the general use php + MySQL or asp + access "golden" combination.

practice

It's not that I recently were using asp + access, but the station is not a business, but a small Teaching Management System.

The development process encountered a problem, gb2312 encoding asp pages are used front and rear end of the front end using ajax to pass the Chinese argument, after the back-end coding process, so as not to deposit access garbled.

Note: The front and rear ends are recommended with utf-8 encoding, so no trouble following.

Front-end code:

$.post("result.asp?act=update",{
  val: escape(val)
},function(result){
  result = JSON.parse(result);
});

Back-end code:

Dim val
val = Trim(vbsUnEscape(request.form("val")))

ECMAScript v3 standard deleted from the escape () function and unescape () function, and against the use of them, so you should use decodeURI () and decodeURIComponent () instead.

… All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. …
… Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. …

https://www-archive.mozilla.org/js/language/E262-3.pdf
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape
Function vbsUnEscape(str)
    Dim i,s,c
    s=""
    For i=1 to Len(str)
        c=Mid(str,i,1)
        If Mid(str,i,2)="%u" and i<=Len(str)-5 Then
            If IsNumeric("&H" & Mid(str,i+2,4)) Then
                s=s & CHRW(CInt("&H" & Mid(str,i+2,4)))
                i=i+5
            Else
                s=s & c
            End If
        ElseIf c="%" and i<=Len(str)-2 Then
            If IsNumeric("&H" & Mid(str,i+1,2)) Then
                s=s & CHRW(CInt("&H" & Mid(str,i+1,2)))
                i=i+2
            Else
                s=s & c
            End If
        Else
            s=s & c
        End If
    Next
    vbsUnEscape=s
End Function

Attached general here do not have access vbsEscape:

'escape时不变的7个符号: *(42) +(43) -(45) .(46) /(47) @(64) _(95)
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

If used in the front-end is encodeURI / encodeURIComponent, rather than escape, then the back end can write like this:

<%
FUNCTION strDecode(str)
    Dim objScript
    Set objScript = Server.CreateObject("ScriptControl")
    objScript.Language = "JavaScript"
    URLDecode = objScript.Eval("decodeURIComponent(""" & str & """.replace(/\+/g,"" ""))")
    Set objScript = NOTHING
END FUNCTION
%>

VbsUnEscape above functions can also be written so!

Original: https://xushanxiang.com/2019/11/asp-ajax-escape.html

Guess you like

Origin www.cnblogs.com/xusx2014/p/11940441.html