读书人

axaj乱码有关问题

发布时间: 2012-02-26 20:19:45 作者: rapoo

axaj乱码问题
我的代码是这样的

index.html

<html>
<head>
<script type= "text/javascript ">
function createxmlhttp()
{
if (window.ActiveXObject)
{
xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}


function ajxSend()
{
createxmlhttp()
var info= "username= "+document.getElementById( "username ").value;
xmlHttp.open( "POST ", "user.asp ", true);
xmlHttp.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");
xmlHttp.onreadystatechange = ajxReceive;
xmlHttp.send(info);
}


function ajxReceive()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
document.getElementById( "p ").innerHTML=xmlHttp.responseText;
}
}

}
</script>
</head>
<body>
<input type= "text " name= "username " id= "username " onblur= 'ajxSend() '>
<span id= "p "> </span>
</body>
</html>


user.asp

<%@LANGUAGE= "VBSCRIPT " CODEPAGE= "936 "%>
<%
Response.ContentType = "text/html "
Response.Charset = "GB2312 "
response.write request( "username ")
response.write "test成功! "
%>


结果response.write request( "username ")显示乱码
response.write "test成功! "正常显示
我要这两个都正常显示应该这样改

[解决办法]
<%@LANGUAGE= "VBSCRIPT "%>
<%
Response.CodePage = 65001 'IIS 5.1 top
Response.ContentType = "text/html "
Response.Charset = "utf-8 "
response.write request( "username ")
response.write "test成功! "
%>

如果是5.0以下版本,则需要自己写函数解析Request.BinaryRead(Request.TotalBytes)的内容

读书人网 >ASP

热点推荐