zoukankan      html  css  js  c++  java
  • asp结合ajax中文乱码问题

    XMLHttpRequest 在w3c标准中这样提到:

    如果响应包含了为响应体指定字符编码的头部,就使用该编码。否则,假定使用 Unicode UTF-8。

    前端页面sele.asp

    <" CODEPAGE="936"%>
    <!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" />
    <script src="selectcustomer.js"></script>
    </head>

    <body>

    <form>
    请输入项目名称:<input name="customers" onkeyup="showCustomer(this.value)" type="text" />

    </form>

    <p>
    <div id="txtHint"><b>项目信息将在此处列出。</b></div>
    </p>

    </body>
    </html>
    ================================================================

    selectcustomer.js页面

    // JavaScript Document
    var xmlHttp

    function showCustomer(str)
    {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
    alert ("您的浏览器不支持AJAX!");
    return;
    }
    var url="getcustomer.asp";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;

    xmlHttp.open("get",url,true);

    xmlHttp.send(null);
    }

    function stateChanged()
    {
    if (xmlHttp.readyState==4)
    {
    document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
    }
    }

    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
    // Internet Explorer
    try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
    catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
    }

    =======================================================

    后端getcustomer.asp页面

    <!--#include file="conn/conn.asp" -->
    <%
    Response.Charset="GB2312"
    Response.ContentType="text/html"
    '加入红色显示的两句就可以解决问题
    response.expires=-1
    strSQL = "select ProjName from Proj where ProjName like '%"&request.querystring("q")&"%'"
    Response.Write(strsql)
    Set RS = Server.CreateObject("ADODB.RecordSet")                 

    RS.open strSQL,Conn,1,1  
    response.write("<table>")
    while not rs.eof
    response.write("<tr><td>")
    response.write("<a href=#>"&rs("ProjName")&"</a>")
    response.write("</td></tr>")
    response.write("</table>")
    response.write("<table>")
    rs.MoveNext
    wend
    response.write("</table>")


    %>

  • 相关阅读:
    并查集分析+总结
    poj 3083 Children of the Candy Corn(bfs+dfs 数组模拟方向)
    poj 1094 Sorting It All Out (拓扑排序)
    poj 2632 Crashing Robots(模拟)
    poj 1068 Parencodings (模拟)
    poj 1273 Drainage Ditches ( 最大流Edmonds_karp算法)
    poj 3278 Catch That Cow (BFS)
    Codeforces Round #109 (Div. 2) 总结
    poj 2299 UltraQuickSort(归并排序)
    poj 1035 Spell checker(字符串)
  • 原文地址:https://www.cnblogs.com/fangmin/p/3333506.html
Copyright © 2011-2022 走看看