yyh820 2016-11-29 00:18 采纳率: 0%
浏览 1317

关于jquery中的+号转义传输方法

 <script type="text/javascript">    
$(function(){        

    $('.quickly tr td').click(function(){ 

    // 屏蔽Enter按键 
$(document).keydown(function(event) { 
switch (event.keyCode) { 
case 13: return false; 
}
}); 

        if(!$(this).is('.input')){    
            $(this).addClass('input').html('<input type="text" value="'+ $(this).text() +'" />').find('input').focus().blur(function(){    
                var thisid = $(this).parent().siblings("th:eq(0)").text();    
                var thisvalue=$(this).val();    
                var thisclass = $(this).parent().attr("class");      

                $.ajax({    
                  type: 'POST',    
                  url: 'ok.asp',   
                  data: "thisid="+thisid+"&thisclass="+thisclass+"&thisvalue="+encodeURI(encodeURI(thisvalue))    
                });    
                $(this).parent().removeClass('input').html($(this).val() || 0);    
            });                        
        }    
    }).hover(function(){    
        $(this).addClass('hover');    
    },function(){    
        $(this).removeClass('hover');    
    });    

});    
</script>


这是一段以前的老代码,后台处理程序是asp的,现在需要在其中填写的内容包括+号,以前只要填写纯数字的,没发现这个问题,现在发现一旦填写了+数据就无法获取,后台处理的程序是这样子的:

<%
Function URLDecode(ByVal urlcode)'URL反编码函数
    Dim start,final,length,char,i,butf8,pass
    Dim leftstr,rightstr,finalstr
    Dim b0,b1,bx,blength,position,u,utf8
    On Error Resume Next

    b0 = Array(192,224,240,248,252,254)
    urlcode = Replace(urlcode,"+"," ")
    pass = 0
    utf8 = -1

    length = Len(urlcode) : start = InStr(urlcode,"%") : final = InStrRev(urlcode,"%")
    If start = 0 or length < 3 Then URLDecode = urlcode : Exit Function
    leftstr = Left(urlcode,start - 1) : rightstr = Right(urlcode,length - 2 - final)

    For i = start To final
        char = Mid(urlcode,i,1)
        If char = "%" Then
            bx = URLDecode_Hex(Mid(urlcode,i + 1,2))
            If bx > 31 And bx < 128 Then
                i = i + 2
                finalstr = finalstr & ChrW(bx)
            ElseIf bx > 127 Then
                i = i + 2
                If utf8 < 0 Then
                    butf8 = 1 : blength = -1 : b1 = bx
                    For position = 4 To 0 Step -1
                        If b1 >= b0(position) And b1 < b0(position + 1) Then
                            blength = position
                            Exit For
                        End If
                    Next
                    If blength > -1 Then
                        For position = 0 To blength
                            b1 = URLDecode_Hex(Mid(urlcode,i + position * 3 + 2,2))
                            If b1 < 128 or b1 > 191 Then butf8 = 0 : Exit For
                        Next
                    Else
                        butf8 = 0
                    End If
                    If butf8 = 1 And blength = 0 Then butf8 = -2
                    If butf8 > -1 And utf8 = -2 Then i = start - 1 : finalstr = "" : pass = 1
                    utf8 = butf8
                End If
                If pass = 0 Then
                    If utf8 = 1 Then
                        b1 = bx : u = 0 : blength = -1
                        For position = 4 To 0 Step -1
                            If b1 >= b0(position) And b1 < b0(position + 1) Then
                                blength = position
                                b1 = (b1 xOr b0(position)) * 64 ^ (position + 1)
                                Exit For
                            End If
                        Next
                        If blength > -1 Then
                            For position = 0 To blength
                                bx = URLDecode_Hex(Mid(urlcode,i + 2,2)) : i = i + 3
                                If bx < 128 or bx > 191 Then u = 0 : Exit For
                                u = u + (bx And 63) * 64 ^ (blength - position)
                            Next
                            If u > 0 Then finalstr = finalstr & ChrW(b1 + u)
                        End If
                    Else
                        b1 = bx * &h100 : u = 0
                        bx = URLDecode_Hex(Mid(urlcode,i + 2,2))
                        If bx > 0 Then
                            u = b1 + bx
                            i = i + 3
                        Else
                            If Left(urlcode,1) = "%" Then
                                u = b1 + Asc(Mid(urlcode,i + 3,1))
                                i = i + 2
                            Else
                                u = b1 + Asc(Mid(urlcode,i + 1,1))
                                i = i + 1
                            End If
                        End If
                        finalstr = finalstr & Chr(u)
                    End If
                Else
                    pass = 0
                End If
            End If
        Else
            finalstr = finalstr & char
        End If
    Next
    URLDecode = leftstr & finalstr & rightstr
End Function

Function URLDecode_Hex(ByVal h)
    On Error Resume Next
    h = "&h" & Trim(h) : URLDecode_Hex = -1
    If Len(h) <> 4 Then Exit Function
    If isNumeric(h) Then URLDecode_Hex = cInt(h)
End Function

'这里是数据连接定义
%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
dim rs
set rs=server.CreateObject("adodb.recordset")
sql="select * from ok where id="&request("thisid")
rs.open sql,connsqloffice,1,3
m=left(request("thisclass"),len(request("thisclass"))-5)
rs(m)=URLDecode(request("thisvalue"))
rs.update
rs.close
set rs=nothing
%>


求助大侠,怎样修改代码,可以正常获取含+的数据呢,谢谢!
  • 写回答

1条回答 默认 最新

  • Go 旅城通票 2016-11-29 04:07
    关注

    data: "thisid="+thisid+"&thisclass="+thisclass+"&thisvalue="+encodeURI(encodeURI(thisvalue))

    encodeURIComponent一次就行了,不需要编码2次,而且编码统一就行,不需要服务器端再解码一次

    asp网站使用utf-8编码注意事项

    评论

报告相同问题?

悬赏问题

  • ¥15 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug