HTML/JS转换工具
Unicode编码转换
当前位置:首页 > WEB前端 > AJAX > 

ajax post 传递中文参数

来源:IT技术网编辑:雨天发布于:2017-05-01人围观

-test.htm--------------------------------------------------------

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ajax测式</title>
<script type =text/Jscript>
//声明XMLHttpRequest
var request = false;
function crea()
{
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = false;
    }
  }
}
//////////////////
if (!request)
  alert("没有成功建立XMLHttpRequest");
}
//---------------------------------
//函数 
function getCustomerInfo() {
crea()
 
var   send_string= 'id='+escape(id.value)+ "&id2="+ escape(id2.value);

 

 
    var p = document.getElementByIdx("id").value;
          var url = "test.asp"
               request.onreadystatechange = upd;
               request.open("post", url, true);
               request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
               request.send(send_string);

 

               //////
   }
  
   //////////////////
function upd(){

 

if (request.readyState == 4)
       if (request.status == 200)
{

 

 

var response = request.responseText.split("|");
document.getElementByIdx('message').innerHTML = response[0];
//document.getElementByIdx('message').innerHTML = response[1];//.........................

 

}
else if (request.status == 404)
    alert("没有找到提取文件");
else
    alert("Error: status code is " + request.status);

 

}

</script>
</head>

<body>

 

<input type=text id="id" name="id">
<input type=text id="id2" name="id2">
<input type=button onClick="getCustomerInfo()" value="提交">
<br>
<font id="message"></font>
<font id="mes"></font>
<br>
------------------------

<!--
·open():建立到服务器的新请求。 <br>
·send():向服务器发送请求。 <br>
·abort():退出当前请求。 <br>
·readyState:提供当前 HTML 的就绪状态。 <br>
·responseText:服务器返回的请求响应文本。
-->

 

</body>

 

</html>

--test.asp------------------------------------------------------------------------

<%
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

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

'-------------------------------------------
'//禁止缓存该页 让AJAX读取该页始终为最新而非过期缓存页
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
'-------------------------------------------
response.Charset="GB2312" '//数据返回的编码类型 显示中文数据必须

'-------------------------------------------
response.Write(now())'//得到当前时间
Dim Content ,Content2
Content = Request.Form("id")
Content2 = Request.Form("id2")

Response.Write "<br>id=" &  vbsUnEscape(Content) & "id2=" & vbsUnEscape(Content2)
%>

织梦二维码生成器

与相关的文章
有时间的话来看看IT界的突发事件
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片