棘手问题!!在线求解:我已经知道这是编码问题,可这有点不可理解!

kokoo916x 2006-10-26 03:43:56
我已经知道这是编码问题,可这有点不可理解!请高手们给个说法,呵呵。
是这样的,我所有文件的编码都是 "utf-8" 的,按理说,Ajax默认传送数据用的就是 utf-8,可为什么当我把下面一个件的编码从 gb2312 改为 utf-8 的时候,却接收不到服务器端的数据。再改回gb2312就一切正常了。下面是源文件:

index.asp:
----------------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!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">'《--就是这里改成utf-8
<title></title> 就会出问题。
</head>
<script language="javascript" src="Ajax.js"></script>
<body onload=javascript:loadGashType();>
<form id="dd" name="fd" method="post" action="">
<select name="ClassName" id="ClassName" onchange="javascript:loadGash();">
<option value="0" selected="selected">请选择</option>
</select>
<select name="nameDot" id="nameDot" >
<option value="0" selected="selected">请选择</option>
</select>
</form>
<div id=statusTxt></div>
</body>
</html>

ajax.js
-------------------------------------
// JavaScript Document
var http_request = false;
function send_request(url,method)
{
http_request = false;
if(window.XMLHttpRequest)
{
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
}
}
}
if (!http_request)
{
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
switch(method)
{
case 1: http_request.onreadystatechange = processRequest1;
break;
case 2: http_request.onreadystatechange = processRequest2;
break;
}
http_request.open("GET",url, true);
http_request.send(null);
}


function processRequest1()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
document.getElementById("statusTxt").innerHTML="";
addOptionGroup("ClassName",http_request.responseText);
}
else
{
alert("您所请求的页面有异常。");
}
}
else
{
document.getElementById("statusTxt").innerHTML="正在读取数据中……";
}
}


function processRequest2()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
document.getElementById("statusTxt").innerHTML="";
addOptionGroup("nameDot",http_request.responseText);
}
else
{
alert("您所请求的页面有异常。");
}
}
else
{
document.getElementById("statusTxt").innerHTML="正则读取数据中……";
}
}


function loadGashType()
{
send_request("select.asp?action=gashType",1);
}


function loadGash()
{
send_request("select.asp?action=gash&id="+document.getElementById("ClassName").value,2);
}


function addOption(objSelectNow,txt,val)
{
var objOption = document.createElement("OPTION");
objOption.text= txt;
objOption.value=val;
objSelectNow.options.add(objOption);
}


function addOptionGroup(selectId,optGroupString)
{
var optGroup = optGroupString.split(",");
var objSelect = document.getElementsByTagName("SELECT");
var objSelectNow = objSelect[selectId];
objSelectNow.length = 1;
for (i=1; i<optGroup.length; i++)
{
if(optGroup[i]!="")
{
var opt = optGroup[i].split("|");
addOption(objSelectNow, opt[0], opt[1]);
}
}
}

select.asp
-------------------------------------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%
response.Buffer=true
Session.CodePage=65001
Response.Charset="utf-8"
dim oConn,DbPath
set oConn=Server.CreateObject("Adodb.Connection")
DbPath=Server.MapPath("data/#mydata.mdb")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath

Set oRs = Server.CreateObject( "ADODB.Recordset" )
action = Request.QueryString("action")

response.Write("请选择|-1,")


if action = "gashType" then
sql = "select * from classDot"
oRs.open sql,oConn,1,3
if not (oRs.eof or oRs.bof) then
while not oRs.eof
Response.Write oRs("classDotName")&"|"&oRs("id")&","
oRs.movenext
wend
end if
oRs.close
elseif action = "gash" then
sql = "select * from [dotcard] where classID ="&Request.QueryString("id")&" and not isdel"
oRs.open sql,oConn,1,3
if not (oRs.eof or oRs.bof) then
while not oRs.eof
Response.Write oRs("dotcard")&"|"&oRs("cardid")&","
oRs.movenext
wend
end if
oRs.close
else
response.Write("程序出错")
end if
oConn.close
%>

//请各个朋友给瞧瞧,给点看法哦,呵呵,我在线呢。
...全文
108 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Eilien 2006-10-28
  • 打赏
  • 举报
回复
先mark

等会回公司再细看。
kokoo916x 2006-10-26
  • 打赏
  • 举报
回复
原因是ajax.js文件非utf-8编码。
kokoo916x 2006-10-26
  • 打赏
  • 举报
回复
问题已经解决,不用麻烦各位大侠了。呵呵
kokoo916x 2006-10-26
  • 打赏
  • 举报
回复
怎么没人看哦。
相关推荐
发帖
Ajax

5.2w+

社区成员

Web 开发 Ajax
社区管理员
  • Ajax
加入社区
帖子事件
创建了帖子
2006-10-26 03:43
社区公告
暂无公告