背景
asp的第一版是0.9測驗版,自從1996年ASP1.0誕生,迄今20余載,雖然asp在Windows2000 IIS服務5.0所附帶的ASP 3.0發布后好像再沒有更新過了,但是由于其入手簡單,天然的asp+access零配置,在零幾年火的就像現在的微信小程式,雖然時過境遷,其至今在國內還有小規模的用戶市場,
據工信部發布訊息,截止到2018年底,中國中小企業的數量已經超過了3000萬家,個體工商戶數量超過7000萬戶,中小企業資訊化普遍面臨資金短缺、資訊人才不足等問題,為了降低成本,故而企業網站一般外包給其他小規模的網路公司制作、維護,網路公司一般是套站、仿站,作業系統一般使用Windows,web程式搭建上,一般使用php+MySQL或者asp+access的“黃金”組合,
實踐
這不,筆者最近又用上了asp+access,不過不是企業站的,而是一個小型的教學管理系統,
開發程序中碰到一個問題,asp頁面前后端都是用的gb2312編碼,前端使用ajax來傳遞中文引數,后端進行編碼處理后,以免存入access為亂碼,
注:建議前后端都是用utf-8編碼,就沒下面這么麻煩了,
前端代碼:
$.post("result.asp?act=update",{ val: escape(val)},function(result){ result = JSON.parse(result);});后端代碼:
Dim valval = Trim(vbsUnEscape(request.form("val")))ECMAScript v3 已從標準中洗掉了 escape() 函式和 unescape() 函式,并反對使用它們,因此應該使用 decodeURI() 和 decodeURIComponent() 取而代之,
… 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. …
https://www-archive.mozilla.org/js/language/E262-3.pdf
… Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. …
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=sEnd Function另附上一般這里用不上的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 = sEnd Function如果,在前端使用的是encodeURI/encodeURIComponent,而不是escape,那么,后端還可以像下面這樣寫:
<%Function strDecode(str) Dim objScript Set objScript = Server.CreateObject("ScriptControl") objScript.Language = "JavaScript" strDecode = objScript.Eval("decodeURIComponent(""" & str & """.replace(/\+/g,"" ""))") Set objScript = NOTHINGEnd Function%>上面的vbsUnEscape函式也可以這么寫!
原文:https://xushanxiang.com/2019/11/asp-ajax-escape.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/28091.html
標籤:jQuery
上一篇:jQuery之概念以及基本使用
