ASP+AJAX用request获取参数的中文值不到

tcmis 2009-07-28 08:59:49
碰到一个奇怪的问题, 我用ASP+AJAX用request获取参数的中文值不到,为空,传数字和字母都可以获取到,
用js显示的时候是有值, 并且显示不是乱码。到asp页面就获取不到中文值了,不知道原因,搞了很久都没有找到原因
大侠们看看什么原因。谢谢了。
function getEmployee(name){
request = createXmlHttpRequestObject();
var url = "../employee/getEmployeeAJAX.asp?name="+name+"&r="+getRandom();
alert(url);
request.open("GET", url, true);
showLoading();
request.onreadystatechange = getEmployeeResult;
request.send(null);
}

<%
Session.CodePage=65001
%>

<!--#include file="../../com/conn.asp" -->
<!--#include file="../../com/jrosion.asp" -->

<%
dim name, result
name = request("name") '这个地方只能获取数字和字母的值。
sql = "select pk, name from V_EMPLOYEE where name = '"&name&"'"
set ds = conn.execute(sql)
if (not ds.eof) then
while (not ds.eof)
result = result&ds("pk")&"^"&ds("name")&"~"
ds.movenext()
wend
end if

response.Write(result)
%>
...全文
338 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
anbs01 2009-07-28
  • 打赏
  • 举报
回复
将编码改成utf-8就好了。
我遇到过这样的问题。
tcmis 2009-07-28
  • 打赏
  • 举报
回复
楼上的可以,非常感谢,谢谢大家给的帮助。
月光下的土豆 2009-07-28
  • 打赏
  • 举报
回复
var url = "../employee/getEmployeeAJAX.asp?name="+escape(name)+"&r="+getRandom();
escape(name) 编码一下。
<%
Response.Charset = "gb2312"
Session.CodePage = 936
...........
%>
tcmis 2009-07-28
  • 打赏
  • 举报
回复
前面我本来就加了的,只是放在最前面
chenjianyong94 2009-07-28
  • 打赏
  • 举报
回复
<%
dim name, result

response.charset="gb2312"

name = request("name") '这个地方只能获取数字和字母的值。
sql = "select pk, name from V_EMPLOYEE where name = '"&name&"'"
set ds = conn.execute(sql)
if (not ds.eof) then
while (not ds.eof)
result = result&ds("pk")&"^"&ds("name")&"~"
ds.movenext()
wend
end if

response.Write(result)
%>

加上字符编码就OK了
tcmis 2009-07-28
  • 打赏
  • 举报
回复
我如果设置成Session.CodePage=936那么乱码
设置成Session.CodePage=65001那么接受不到数据。
tcmis 2009-07-28
  • 打赏
  • 举报
回复
是乱码。
Atai-Lu 2009-07-28
  • 打赏
  • 举报
回复
是无法获取还是获取的值是乱码???
tcmis 2009-07-28
  • 打赏
  • 举报
回复
全试了,还是不行。。
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 tcmis 的回复:]
在传递的时候用了encodeURIComponent函数,那在asp页面通过什么函数来解析呢?
[/Quote]
encodeURIComponent与Server.URLEncode基本一样的
tcmis 2009-07-28
  • 打赏
  • 举报
回复
在传递的时候用了encodeURIComponent函数,那在asp页面通过什么函数来解析呢?
  • 打赏
  • 举报
回复
你在服务端先用Response.Charset("GB2312")这个试试,不行再按以上方法
tcmis 2009-07-28
  • 打赏
  • 举报
回复
不知道要改些什么地方呢?
我把编码改成utf-8,gbk,gb2312都试了,还是不行。
连在连接数据库的文件里面加了编码格式也不行,都崩溃了。
  • 打赏
  • 举报
回复
你发送页面和接受页面都用UTF-8的编码,然后参数传递时用encodeURIComponent方法将参数进行编码
这样就能解决了,要不然你就得服务器端进行转换
  • 打赏
  • 举报
回复
估计编码原因
默认是UTF-8的

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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