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