Asp and ajax Chinese garbled characters

Source: Internet
Author: User

XMLHttpRequest mentioned in w3c standards as follows:

If the response contains a header that specifies the character encoding for the response body, this encoding is used. Otherwise, it is assumed that the Unicode UTF-8 is used.

Front-end page 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>
Enter the Project name: <input name = "customers" onkeyup = "showCustomer (this. value)" type = "text"/>

</Form>

<P>
<Div id = "txtHint"> <B> project information is listed here. </B> </div>
</P>

</Body>
</Html>
========================================================== ======================================

Selectcustomer. js page

 

// JavaScript Document
Var xmlHttp

Function showCustomer (str)
{
XmlHttp = GetXmlHttpObject ();
If (xmlHttp = null)
{
Alert ("your browser does not support 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;
}

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

Backend getcustomer. asp page

<! -- # Include file = "conn/conn. asp" -->
<%
Response. Charset = "GB2312"
Response. ContentType = "text/html"
'The problem can be solved by adding two sentences in red.
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> ")


%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.