All my web page encoding is utf-8. When the browser is opened and does not insert data into the database (main.asp), it directly reads the data and browses (showAll.asp), and everything is normal; but when the main.asp inserts the data into the access table through ajax, and then browses the showAll.asp page, all the contents in the Response.Write('Chinese') statement are garbled, even if the showAll.asp page does not contain data from the database, it is still garbled. When I edited the browsed web page source code in a notebook, I found that his encoding became ANSI.
So just add it in front of the showAll.asp page
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
<%Session.CodePage=65001%> can solve the problem.
If your web page is UTF-8 encoding, please add it to the first line of the code:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>
If your web page is encoded based on GB2312, please add it to the first line of the code:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>
Note: I solved the ASP garbled code through this method. Please note 2 points here
1.<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%> This line of code must be placed on the first line of the page
This is the point:
2.<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> and <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> and <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
response.write method to output utf-8
In order to adapt to the needs of the XMLHTTP control, this control can only get the correct output when obtaining the utf-8-encoded web page content. I tried various methods and even used adodb.steam to transcode on the asp server. Later, I saw an article, just add the following code to the asp. I tried it and it was successful! Just don't know why.
Response.ContentType="text/html"
Response.AddHeader"Content-Type","text/html;charset=UTF-8"
Response.CodePage=65001
Response.CharSet="UTF-8"
Response.BinaryWrite(chrb(239))
Response.BinaryWrite(chrb(187))
Response.BinaryWrite(chrb(191))
Next, use response.write to directly output the content, and the client will get the content encoded in utf-8.
Response.write Solution to output garbled code
In many cases, we don't pay much attention to some details.
For example, during the development of Asp, the most troublesome thing is the decoding problem of web pages
I am developing some traditional Chinese websites now, and the company stipulates that the international decoding of utf-8 is required.
So the decoding problem will bother you...
Let's not look at the smallest <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
This code is because this code is very useful, especially in decoding. For example, many people will have garbled code when using the response.write method to output Chinese strings, and no matter how you add response.charset="utf-8" and session.codepage=65001, it will be of no help, so we need <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>