请教ASP中采用ajax获取数据库中中文字段内容返回页面时乱码问题

于之 2017-12-13 04:08:21
请教ASP中采用ajax获取数据库中中文字段内容返回页面时乱码问题

我的页面:

a.html
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
<!--
$(function(){
$('.SM').click(function(){
$.ajax({
type: "GET",
url: "b.asp",
dataType: "text",
success: function(data){
$('#right_resText').empty(); //清空resText里面的所有内容
var html = data;
$('#right_resText').html(html);
}
});
});

});
//-->
</script>
...


而其中的调用b.asp获取数据库中的数据。

b.asp
<%Response.Charset = "GB2312"%>
<!--#include file=cxaxbbs_conn.asp-->
<%
exec="select top 5 ctype,title from testdb where id2=-1 and cancelled=0 order by id desc"
set rs=server.createobject("adodb.recordset")
i=1
rs.open exec,conn,1,1
'response.Charset ="gb2312"
do while not rs.eof
ntitle=rs("title")
ntype=rs("ctype")
response.write "{""data"":["
response.write "{""title"":"&ntitle&",""ctype"":"""&ntype&"""}"

rs.movenext
i=i+1
loop
set rs=nothing

%>

结果运行 a.asp页面时,获取到的中文全为乱码,网上百度了很多,但一一试了不行,请大神指教,谢谢
...全文
483 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hididi 2017-12-14
  • 打赏
  • 举报
回复
b.asp顶部加上<%@ CodePage=936 %>,然后要确保两个文件的编码都是Ansi的。

52,792

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧