asp结合ajax中文乱码问题_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > asp结合ajax中文乱码问题

asp结合ajax中文乱码问题

 2013/9/22 18:27:25  I是初学者  博客园  我要评论(0)
  • 摘要:XMLHttpRequest在w3c标准中这样提到:如果响应包含了为响应体指定字符编码的头部,就使用该编码。否则,假定使用UnicodeUTF-8。前端页面sele.asp<"CODEPAGE="936"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http
  • 标签:文乱码问题 Ajax 文乱码 问题 结合 乱码问题

XMLHttpRequest 在w3c标准中这样提到:

如果响应包含了为响应体指定字符编码的头部,就使用该编码。否则,假定使用 Unicode UTF-8。

前端页面sele.asp

<" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="selectcustomer.js"></script>
</head>

<body>

<form>
请输入项目名称:<input name="customers" onkeyup="showCustomer(this.value)" type="text" />

</form>

<p>
<div id="txtHint"><b>项目信息将在此处列出。</b></div>
</p>

</body>
</html>
================================================================

selectcustomer.js页面

 

// JavaScript Document
var xmlHttp

function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}
var url="getcustomer.asp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;

xmlHttp.open("get",url,true);

xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
}
return xmlHttp;
}

=======================================================

后端getcustomer.asp页面

<!--#include file="conn/conn.asp" -->
<%
Response.Charset="GB2312"
Response.ContentType="text/html"
'加入红色显示的两句就可以解决问题
response.expires=-1
strSQL = "select ProjName from Proj where ProjName like '%"&request.querystring("q")&"%'"
Response.Write(strsql)
Set RS = Server.CreateObject("ADODB.RecordSet")                 

RS.open strSQL,Conn,1,1  
response.write("<table>")
while not rs.eof
response.write("<tr><td>")
response.write("<a href=#>"&rs("ProjName")&"</a>")
response.write("</td></tr>")
response.write("</table>")
response.write("<table>")
rs.MoveNext
wend
response.write("</table>")


%>

发表评论
用户名: 匿名