AJax显示ASP从Access数据库中显出出来的数据 乱码 ~急~ 在线等! - Web 开发 / Ajax
我写的一个程序,用ajax和asp通信,把asp页面从数据库中提取出来的数据显示到网页中去,但是显示出来的是乱码,现把代码贴出,请各位帮忙,谢谢!
网页代码:
<div id="showArticleDiv"></div>
<select id="pages" onchange="javascript:ShowPage()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Ajax js 代码:
var xmlhttp = false;
function ShowPage()
{
var url = "CallBack.asp?page=" + document.getElementById("pages").value;
createXMLHTTP();
xmlhttp.open("GET",url,true);
//xmlhttp.setRequestHeader("CONTENT-TYPE","text/html;Charset=gb2312");
xmlhttp.onreadyStatechange = callBack;
xmlhttp.send(null);
}
function callBack()
{
if(xmlhttp.readyState == 4)
{
//alert(xmlhttp.status);
if(xmlhttp.status == 200)
{
alert(xmlhttp.responseText);
var showArticleDivContent = document.getElementById("showArticleDiv");
showArticleDivContent.className = 'show';
//xmlhttp.setRequestHeader("CONTENT-TYPE","text/html;Charset=gb2312");
showArticleDivContent.innerHTML = xmlhttp.responseText;
}
}
}
function createXMLHTTP()
{
try
{
xmlhttp = new ActiveXObjext("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
}
catch(E)
{
xmlhttp = false;
}
}
}
Ajax 访问后台代码:
sqlstr="select * from Article Where ClassID = 9 and Deleted = false"
call rsCon(rs,sqlstr) '本人自己定义的一个方法
response.Write "<TABLE cellSpacing=0 cellPadding=0 width=90% align=center border=0>"
response.Write "<TBODY>"
response.Write "<TR><TD height=15> </TD></TR>"
if rs.eof then
response.Write "<TR><TD bgColor=#ffffff height=22>• NO content</TD></TR>"
response.Write "<TR><TD style='FONT-SIZE: 1mm' height=1> </TD></TR>"
else
if clng(request.QueryString("page")) <> 1 then
rs.AbsolutePosition = (clng(request.QueryString("page"))-1) * 16-1
end if
i = 0
while i < 16 and not rs.eof
response.Write "<TR><TD bgColor=#ffffff height=22>• <a href='ShowArticle.asp?ArticleID="&rs("ArticleID")&"'>"&rs("Title")&"</A></TD></TR>"
response.Write "<TR><TD style='FONT-SIZE: 1mm' height=1> </TD></TR>"
i = i + 1
rs.movenext
wend
end if
response.Write "<TR><TD style='FONT-SIZE: 1mm' height=1> </TD></TR>"
response.Write "<TR><TD height=15> "&request.QueryString("page")&"</TD></TR></TBODY></TABLE>"
------解决方案--------------------当有中文时请使用XML文件格式作为信息的载体
------解决方案--------------------asp文件
VBScript code
dim xml
xml="<?xml version='1.0' encoding='gb2312'?>"
xml=xml&"<body><![CDATA["
sqlstr="select * from Article Where