JS is often called in Asp.net.CodeIf JS is written in Asp.net, it will not be garbled. Because they have the same encoding.
If you need to reference external JavaScript code, there is a risk of garbled code. Under normal circumstances Asp.net and JavaScript page encoding is not gb2312 is the Utf-8, if the two encoding inconsistency will produce garbled. The solution is to unify the encoding of the two.
Since Asp.net generally accepts the encoding for sending requests is Utf-8, the default JavaScript encoding is gb2312, so it is prone to problems.
In Asp.net, you can set sending encoding in two places.
1. Add in Web. config
< System. Web >
< Globalization Requestencoding = "UTF-8" Responseencoding = "UTF-8" />
</ System. Web >
2. Add the following content to the ASPX page file:
<% @ Page contenttype = " Text/html " Responseencoding = " UTF-8 " %>
Solutions in Javascript
1. Save the JS file as the specified encoding, such as converting from ANSI to UTF-8.
2. Add the charset attribute When referencing the JS statement generated by Asp.net.
< Script SRC = ' Http: // localhost/varshop/shopwelcome. aspx? Code = 48090001 ' Language = ' Javascript ' Charset = ' UTF-8 ' > </ Script >
If the problem persists, another important reason is the browser cache. You need to clear the browser cache. After the browser loads the latest file, garbled characters will disappear.