关于ajax的分页问题
我用ajax技术做了一个分页,显示的时候就会乱码index.asp
<div id="content">
<div id="main"></div></div>
<script type="text/javascript">
function FF(y) {
if (!y) {
y=1;
}
var xmlhttp;
if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
if (xmlhttp) {
xmlhttp.onreadystatechange=function () {
if(xmlhttp.readyState==4) {
if(xmlhttp.status==200) {
var yy=unescape(xmlhttp.responseText);
show(yy);
}else {
alert("error");
}
}
}
xmlhttp.open("get","page.asp?page="+y);
xmlhttp.send(null);
}
}
function show(text) {
document.getElementById("main").innerHTML=text;
}
</script>
page.asp
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
dim conn,rs
dim connstr,sqlcmd
set conn=server.CreateObject("ADODB.connection")
connstr="Driver={Microsoft Access Driver (*.mdb)};dbq="&server.MapPath("data#web/db1.mdb")
conn.open connstr
set rs=server.CreateObject("ADODB.recordset")
sqlcmd="select bla_title,bla_time,bla_id,bla_intro,bla_flag,bla_click from bl_article"
rs.open sqlcmd,conn,1,1
rs.pagesize=3
page=clng(request.QueryString("page"))
if page<1 then page=1
if page>rs.pagecount then page=rs.pagecount
rs.absolutepage=page
for i=1 to rs.pagesize
response.Write("<dl><dd>")
response.Write("<h2><a href='log_detail.asp?id="&rs(2)&"'>"&escape(rs(0))&"</a></h2>")
response.Write("<h5>添加时间(就是这里的中文“添加时间”显示乱码):"&escape(rs(1))&" "&escape(rs(4))&" "&escape(rs(5))&"</h5>"&escape(rs(3))&"")
response.Write("</dl></dd>")
rs.movenext
if rs.EOF then exit for
next
if page=1 then
response.write(escape("首页 上一页"))
response.write("<a href='javascript:FF("&(page+1)&")'>"&escape("下一页")&"</a>")
response.write("<a href='javascript:FF("&rs.pagecount&")'>"&escape("末页")&"</a>")
elseif page=rs.pagecount then
response.write("<a href='javascript:FF(1)'>"&escape("首页")&"</a>")
response.write("<a href='javascript:FF("&(page-1)&")'>"&escape("上一页")&"</a>")
response.write(escape("下一页 末页"))
else
response.write("<a href='javascript:FF(1)'>"&escape("首页")&"</a>")
response.write("<a href='javascript:FF("&(page-1)&")'>"&escape("上一页")&"</a>")
response.write("<a href='javascript:FF("&(page+1)&")'>"&escape("下一页")&"</a>")
response.write("<a href='javascript:FF("&rs.pagecount&")'>"&escape("末页")&"</a>")
end if
%>
如果不写上“添加时间”就不会乱码 index.asp 编码是utf-8的。page.asp是gb2312的。