Wrong charset in ASP classic loaded via AJAX

狂风中的少年 提交于 2019-12-24 06:39:08

问题


I have issue with dynamic loading of part of content on ASP classic page. I use AJAX to load on page dynamically, depending on dropdown selected option. Generated contains some Labels for containing dropdowns and option text inside of dropdowns. Labels are constants encoded in UTF-8 and contain some western European accented characters, and option texts are loaded from database, contain accented characters too but are coded in ANSI. tags are set to utf-8 but it affects only first load of page, cos its all put together on page. After selecting other options, AJAX fills with elements and it loads labels well but options text is messed up, so i guess AJAX doesnt load up encoding with text second and etc. times. Work-around was to change label text in constants and set <% Response.Charset = "windows-1252" %> on page that is beeing loaded first time. Now, i want to find better way for this, prefferably in AJAX response to set it all to UTF-8 or windows-1225, or to set each element on page to have different coding with ajax. I even tried Replace function from ASP classic, it works , but again it needs for each new accented letter other replace. Any help appreciated! :)


回答1:


I think the best way to solve encoding issues is to switch to utf-8. Not only does it take away the headache of handling special characters in your own language, but pretty much (as I understand utf-8) all languages!

First, include the following meta-tag in the HTML head.

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

You will also need to set UTF-8 at the top of all asp-files that are involved.

response.codepage = 65001
response.charset = "utf-8" 

Do note though that characters posted to and from your asp-pages (via a form for example) will be interpreted as utf-8. Internally in the script engine strings is stored as unicode. Make sure that consistently save the data as unicode in the database.

Read the answer to this question for more in-depth information



来源:https://stackoverflow.com/questions/9716693/wrong-charset-in-asp-classic-loaded-via-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!