CNET中国旗舰网站

ZDNet China | CNET科技资讯网 | 政府采购 | 行业网站联盟





 
标题: [讨论] 棘手问题!!在线求解:我已经知道这是编码问题,可这有点不可理解!
小玩将
支柱会员
Rank: 10Rank: 10Rank: 10



UID 319552
精华 3
积分 16584
帖子 1526
威望 7556
ZD币 2005 元
阅读权限 210
注册 2008-4-16
状态 离线
  楼主
发表于 2008-4-17 14:52  资料  个人空间  短消息  加为好友 
开发者在线

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

我已经知道这是编码问题,可这有点不可理解!请高手们给个说法,呵呵。   
  是这样的,我所有文件的编码都是   "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"   c>'《--就是这里改成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"   >   
  <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!="")   
  {   
  var   opt   =   optGroup.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   
  %>   
   
  //请各个朋友给瞧瞧,给点看法哦,呵呵,我在线呢。




顶部
热点频道推荐: C/S开发| 数据库| WEB开发| 嵌入式| 项目管理|
 



当前时区 GMT+8, 现在时间是 2009-7-5 08:28

  Powered by Discuz! 5.5.0 © 2001-2007 Comsenz Inc.
Processed in 0.065519 second(s), 3/3 queries

清除 Cookies - 联系我们 - ZDNetChina中文社区 - 无图版