Solve the garbled problem caused by different JavaScript codes.

Source: Internet
Author: User

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.

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.