为什么非ascii字符显示为怪异的符号? [英] Why non-ascii chars are displayed as weird symbols?
问题描述
我在这里有两种情况:
我的数据库包含很多我想要获取的信息,其中一些信息是名称,其中包含非ascii字符如 UweRülke
- 旧解决方案效果不错:
< BR>
我从数据库中获取数据,并直接从 VB 填充页面,同时
循环。在这种情况下,所有字符都能正确显示 UweRülke
- 无法正常工作的新解决方案正确:
VB的 while
循环不会直接将数据扔到页面,而是在一个JS字符串中通过不时地调用数据库来提高性能)。但是当我使用存储在JS变量中的信息时,我得到了如下所示: UweR lke
。
在这两种情况下,页面的编码为:
< meta http-equiv =Content-Typecontent =text / html ; charset = iso-8859-1>
我在哪里出错了?
编辑
这是用于从数据库获取js Strings
我使用 AJAX LOAD
从 ISEquery
来构建一个特定的请求并从数据库中查询它。它用于以 excel
文件或普通 HTML
的形式获取数据。
exctractFields
函数 $(< div>< / div> ).load(ISEquery.asp?isExcel = 0&+ info,function(){
//将字段提取到数组中
var rows =;
var options =;
$(this).children()。each(function(index){
var fieldsArray = exctractFields($(this).html());
rows + = createISELine(fieldsArray);
options + = createISELine_ComboBox(fieldsArray);
});
});
感谢Aaron Digulla的answer ,我跟踪了从服务器到页面的字符串,发现它在 所以最终的答案是: - 编写Ajax数据: 现在字符显示正确。 I have 2 cases here: My Database contains lots of info which I want to fetch to the page, some of these info are name which contain non-ascii chars like - Old solution which works well: - New solution which doesn't work properly: In both cases the page's encoding is : AJAX LOAD
,所以我找到了解决我的问题的答案。尽管我必须使用 charset =iso-8859-1
来工作,而不是 charset =UTF-8$
-Encoding在HTML页面中:
< meta http-equiv =Content-Typecontent =text / html;字符集= ISO-8859-1 >
<$ p $ {$ b $''beforeSend':function(xhr){
xhr.overrideMimeType('text / html; charset = iso-8859-1'); $ p $ $ .ajaxSetup
},
});
感谢你们的帮助。Uwe Rülke
I fetch the data from DB and populate the page directly from a VB while
loop. In this case all the chars are displaying correctly Uwe Rülke
The VB's While
loop doesn't throw the data directly to the page, rather in a JS strings (to enhance performance by not calling DB each now and then). but when I use the info stored in the JS variables I got something like this: Uwe R�lke
.<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
Where did I go wrong ? EDIT
This is the code used to Fetch (from DB) then save to js Strings.
I'm using AJAX LOAD
from a page called ISEquery
to build a specific request and query it from DB. It is used to either fetch data as an excel
file or as plain HTML
. At this point the chars are well represented.
Then the magic happens, and the chars get mis-represented, I checked it in the exctractFields
function
$("<div></div>").load("ISEquery.asp?isExcel=0&" + info, function(){
// Extracting the fields into an array
var rows = "";
var options = "";
$(this).children().each(function(index){
var fieldsArray = exctractFields($(this).html());
rows += createISELine(fieldsArray);
options += createISELine_ComboBox(fieldsArray);
});
});
Thanks to Aaron Digulla's answer, I followed the string from server to the page and found that it is gets misrepresented after the AJAX LOAD
, so I found this answer which resolved my problem. Although I had to use the charset="iso-8859-1"
for it to work rather than charset="UTF-8"
.
So the final answer is:
-Encoding in the HTML page:
<meta http-equiv="Content-Type" content="text/html"; charset="iso-8859-1">
-Encoding the Ajax data:
$.ajaxSetup({
'beforeSend' : function(xhr) {
xhr.overrideMimeType('text/html; charset=iso-8859-1');
},
});
And now chars are displayed correctly. Thanx for your help guys..
这篇关于为什么非ascii字符显示为怪异的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!