In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to solve the Chinese garbled problem of introducing external js files in asp.net. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In asp.net, you often need to call js code, if js is written in asp.net, there is generally no garbled problem. Because they have the same code. There is a risk of garbled code if you need to reference external javascript code. In general, the page codes of Asp.net and Javascript are either GB2312 or Utf-8, and garbled will occur if the two codes are inconsistent. The solution is to unify the coding of the two. In general, the encoding of Asp.net to accept and send requests is Utf-8, and the javascript encoding is Gb2312 by default, so it is prone to problems.
You can set the accept send code in two places in Asp.net
Add to 1.Web.config
Add to the 2.Aspx page file
3. Add the following sentence to the page load event:
Response.ContentEncoding = System.Text.Encoding.GetEncoding ("GB2312")
Today, I am writing AJAX code, but there is a very strange problem, that is, all Chinese has become garbled. It has been studied for a long time and checked on the Internet. Basically, the default coding for AJAX asynchronous transmission is UTF-8, while the default coding for asp.net is not this, which is why there is such a garbled problem.
So using. Net Encoding to do a lot of coding conversion experiments, the result is still garbled.
Finally, he was discouraged and asked Louis to take a look. Louis did a very simple test and inserted a sentence into my js code: alert ("Chinese")
It should be able to display in this way, because it has not been processed by asp.net. But guess what? Unexpectedly, it is also garbled. Depressed. Louis said they had encountered this problem before and finally checked out that it was a problem with the encoding of js files. And then I stopped studying when I was getting off work.
When I got home, I carefully did an experiment and copied the contents of the .js file directly into the script tag in the .aspx file, so that it could be displayed normally. Haha. It is said on the Internet that javascript is encoded by utf-8, so I saved the code of the .js file as utf-8, and it was a success. The specific approach is to open a js file in vs2003, save it as, do not change the file name when saving, keep the original, to ensure that the original file is overwritten, and choose the encoding method for the signed UTF-8.
Thank you for reading! This is the end of this article on "how to solve the problem of Chinese garbled code in external js files in asp.net". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.