網頁編碼更改後無法正確執行

阿弟
主程式 KeyInArea.asp (utf-8)

<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<% Response.CharSet = "utf-8" %>
<% Session.codepage = 65001 %>
<html>
<head>
<title>中文區域輸入作業</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body onload="myForm.select1.focus()">
<%
Dim strDSN, objDBConn, strSQL, objRS, I
strDSN = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.Mappath("../database/address.mdb")
Set objDBConn = Server.CreateObject("ADODB.Connection")
objDBConn.Open strDSN
objDBConn.CommandTimeout = 600
set objRS = Server.CreateObject("ADODB.RECORDSET")
%>
<form style="margin:0px;" action="" name="myForm" method="POST">
縣市︰<select name="select1" style="width:100px" OnChange="javascript:document.getElementById('SQL').src='sql.asp?select=1&choice1='+document.getElementById('select1').value;">
  <option value=""></option>
  <%
  strSQL = "select distinct col1 as cname from zipcode"
  If objRS.State = 1 Then objRS.Close
  objRS.Open strSQL, objDBConn, 3, 1

  If objRS.recordcount >0 then
    For I = 1 to objRS.Recordcount 
      Response.Write("<option value=" & objRS("cname") & ">" & objRS("cname") & "</option>")
      If I < objRS.Recordcount then objRS.Movenext
    Next
  End If 
  %>
  </select>
<br><br>
鄉鎮︰<select name="select2" style="width:100px"></select>
</form>
<iframe name="SQL" id="SQL" style="display:none;" src="about:blank"></iframe>
<%
If objRS.State = 1 Then objRS.close
If objDBConn.State = 1 Then objDBConn.close
set objRS = Nothing
set objDBConn = Nothing
%>
</body>
</html>


副程式 sql.asp (big5) 背景取值用

<% Response.CharSet = "big5" %>
<% Session.codepage = 950 %>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<%
Dim strDSN, objDBConn, strSQL, objRS, I
strDSN = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.Mappath("../database/address.mdb")
Set objDBConn = Server.CreateObject("ADODB.Connection")
objDBConn.Open strDSN
objDBConn.CommandTimeout = 600
set objRS = Server.CreateObject("ADODB.RECORDSET")

If Request.QueryString("select") = "1" Then
  strSQL = "select distinct col2 as cname from zipcode where col1='" & Request.QueryString("choice1") & "'"
  Response.Write "<Script Language='JavaScript'>"
  Response.Write "  parent.document.myForm.select2.length=0;"
  Response.Write "  var obj = parent.document.myForm.select2;"
  Response.Write "</script>"
End if

IF objRS.State = 1 Then objRS.close
objRS.OPEN strSQL ,objDBConn ,3, 1

If objRS.recordcount > 0 Then
  Response.Write "<Script Language='JavaScript'>"
  Response.Write "  obj.options[0]=new Option('','');"
  Response.Write "</script>"
  For I = 1 to objRS.recordcount
    Response.Write "<Script Language='JavaScript'>"
    Response.Write "	var oOption = document.createElement('OPTION');"
    Response.Write "	obj.options.add(oOption);"
    Response.Write "	oOption.innerText = '" & objRS("cname") & "';"
    Response.Write "	oOption.value = '" & objRS("cname") & "';"
    Response.Write "</script>"
    If I < objRS.recordcount then objRS.MoveNext
  Next
End If

If objRS.State = 1 Then objRS.close
If objDBConn.State = 1 Then objDBConn.close
set objRS = Nothing
set objDBConn = Nothing
%>
</html>


目前只有IE可正常執行,(Chrom不能跑-原因不明)
但是只要更改 sql.asp 的編碼就連IE都不能跑了
(sql.asp 前六行改成以下)

<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<% Response.CharSet = "utf-8" %>
<% Session.codepage = 65001 %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

第二階-鄉鎮-的部分就撈不出來,請各位先進們不吝指教~~
缺氧的羊:窒息
改成65001之後, [檔案本身]有存成utf8嗎(含bom的)
阿弟
主程式 KeyInArea.asp (utf-8) 中
第一階-縣市-的部分本身就是utf-8
(不需透過sql.asp讀取資料庫)一直都沒問題!!
...(MDB要如何得知是什麼編碼??)
問題出在第二階-鄉鎮-的部分是要透過sql.asp到
資料庫讀取的,只要一改編碼就讀不到了~~
阿弟
To:小羊
KeyInAdd.asp 和 sql.asp 兩個檔案都是存成 UTF-8 格式
-------------------------------------------------
缺氧的羊:窒息
你改成utf8, 然後直接用瀏覽器連到sql.asp, 就可以從html的原始碼去看到讀取出來的內容是否有問題

(chrome可以用F12直接看console是否有javascript的錯誤)
香帥
我有將您的程式碼,放到我的server,並用我的mdb,執行時顯示sql.asp 第25行顯示少了一個運算元,方便的話,可將您的mdb檔案刪除剩3筆上傳供人下載測試,以便找出問題。
老頑童
用big5能跑,代表你mdb裏存的資料也是big5的
改成utf8時,跑到這行
strSQL = "select distinct col2 as cname from zipcode where col1='" & Request.QueryString("choice1") & "'"
變成用utf8跟big5做比對,應該會找不到資料
可能因此沒有顯示任何資料
試著建一筆純英數的資料執行看看,就知道是不是這個原因了
回到頂部