Here we sort out the problem of garbled code under the asp page. There are many solutions to garbled code in many data read by Ajax. The solution principles are the same in garbled code in asp.net, php and other languages. This is a problem with web encoding. In Chinese, gb2312 is generally used, so if you show that Chinese is basically not garbled. But sometimes we use an internationally common utf-8 format. If people don’t know much about the utf-8 format, they are prone to garbled code.
Many friends have asked me why the codepage specified in ASP is 65001 and it often displays garbled codes. The talented man will explain this question in detail here to avoid many friends taking detours and even rejecting UTF-8.
Asp web page utf8 garbled code If you don’t know what UTF-8 is, then Caizi suggests that you search for UTF-8’s related information first.
It is certainly reasonable that UTF-8 encoding is accepted and even liked by more and more people. Today, when WEB2.0 is popular, while talking about multi-browser compatibility, I have to think of the different character encodings caused by different character encodings. Garbage code also needs to be handled well...
N years ago, all versions below IE6 would be garbled if they did not have the corresponding font library installed. For example, I am the version of IE5 (the default of Windows 2000). Without the IE traditional font library installed, Websites that visit any traditional page will be garbled. Of course, the premise is that the page uses BIG5's Charset, and UTF-8 can handle this problem well as an international encoding. As long as the page is saved as UTF-8 encoding Format, then define codepage and charset as utf-8 on the page to display the completely correct content in any client browser without any garbled code...
Okay, Caizi takes the ASP page as an example and takes an example to see the specific operation:
In this case, Caizi recommended using Editplus to write code. Caizi also wrote a tutorial on using Editplus. Interested friends can click here to check it out.
Open a new ASP page, I believe that friends who play ASP will notice that in many downloaded source codes, there is usually a sentence at the top of the page:
<%@LANGUAGE=VBSCRIPTCODEPAGE=936%>
There is no need to say much about the previous language. vbscript is the default scripting language for ASP. In fact, it is not necessary to write. If you write it, it will also affect the page execution efficiency. We will not discuss this issue here. The codepage behind is the key, and the purpose is It tells the browser what kind of encoding this page is. 936 means simplified Chinese, while 950 means traditional Chinese, and 65001 is what we are talking about today's UTF-8 encoding. We change 936 to 65001, and the whole sentence is as follows:
<%@LANGUAGE=VBSCRIPTCODEPAGE=65001%>
Add a few Chinese characters to see if they can be displayed correctly.
<%
Response.Write tests UTF-8 page for the first time
%>
OK, just click Save and execute this page to see. If nothing unexpected happens, you may see that the words UTF-8 pages are displayed. There is garbled Chinese. What is the reason?
OK, please click on the top file menu and select Save As. There is a code on the bottom line. The default should be ANSI. Please click the drop-down box, select UTF-8, click Save, and then try it. If Anyway, it's even more messy. Haha, I'm dizzy. Don't worry, think about the reason, because the page we made is returned by HTML. When we wrote HTML, we saw that there were in front of the body, that is, in the head. A meta sentence should look like this:
<metahttp-equiv=Content-Typecontent=text/html;charset=gb2312>
That is, the specified page returns the result with gb2312 encoding, and must be written in front of the output of the return result. Everyone knows that gb2312 is simplified Chinese. What we are talking about today is UTF-8 encoding, so we will change gb2312 to UTF-8. , all codes are as follows:
<%@LANGUAGE=VBSCRIPTCODEPAGE=65001%>
<metahttp-equiv=Content-Typecontent=text/html;charset=utf-8>
<%
Response.Write tests UTF-8 page for the first time
%>
Execute again, well, it will be displayed normally this time...
Asp web page utf8 garbled conclusion: UTF-8 encoding is used. In addition to saving the file as UTF-8 format, you also need to specify codepage and charset at the same time.
The code that ensures that the asp leaf will not appear garbled should be like this:
(Assuming it is the leaf of UTF-8)
<%@CODEPAGE=65001%>
<%Response.CodePage=65001%>
<%Response.Charset=UTF-8%>
You can create a public file code.asp, and all pages contain this encoding specification.