背景

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 val
val = 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. …
… 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

另附上一般这里用不上的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

如果,在前端使用的是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 = NOTHING
End Function
%>

上面的vbsUnEscape函数也可以这么写!

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

最新文章

  1. 天气预报API(三):免费接口测试(“旧编码”)
  2. Nginx upstream 长连接
  3. Ubuntu 启动栏添加eclipse图标
  4. fancybox 关闭弹出窗口 parent.$.fancybox.close(); 无反应 fancybox 关闭弹出窗口父页面自动刷新,弹出子窗口前后事件
  5. GeoServer地图开发解决方案
  6. showMonth
  7. Codeforces 235E Number Challenge
  8. centos 6.7 perl 版本 This is perl 5, version 22 安装DBI DBD
  9. 正常启动HBase顺序
  10. xadmin与admin设置
  11. 理解 Git
  12. Dispatch Group
  13. c# 读取json文件信息
  14. tp5.1的安装与运行流程
  15. 聚合函数与F/Q表达式
  16. oracle错误汇总1
  17. python点滴:读取和整合文件夹下的所有文件
  18. 提升HTML5的性能体验系列之二 列表流畅滑动
  19. hbase和zookeeper的安装和部署
  20. Sql Over的用法

热门文章

  1. 使PC端网页宽度自适应手机屏幕大小
  2. Python 中文乱码matplotlib乱码 (Windows)
  3. 主流 CSS 布局(水平居中、垂直居中、居中 )
  4. R.Swift优雅加载资源文件
  5. 使用XPath
  6. [考试反思]0810NOIP模拟测试16:黎明
  7. 【PyTorch教程】P3. Python学习中的两大法宝函数(当然也可以用在PyTorch)
  8. 卡特兰数&amp;&amp;prufer序列&amp;&amp;BSGS水题集
  9. SAP HCM 评估路径
  10. Python 基础之socket编程(三)