jQuery AJAX字符编码 [英] jQuery AJAX Character Encoding
问题描述
我目前正在编写一个法语网站。有一个日程表页面,其中一个链接可以用来加载另一天的日程安排。
I'm currently coding a French website. There's a schedule page, where a link on the side can be used to load another day's schedule.
这里是我使用的JS:
<script type="text/javascript">
function load(y) {
$.get(y,function(d) {
$("#replace").html(d);
mod();
});
}
function mod() {
$("#dates a").click(function() {
y = $(this).attr("href");
load(y);
return false;
});
}
mod();
</script>
实际的AJAX就像一个charm。我的问题在于对请求的响应。
The actual AJAX works like a charm. My problem lies with the response to the request.
因为它是一个法国网站,有许多重音字母。我使用ISO-8859-15字符集的原因。但是,在对我的AJAX请求的响应中,口音正在变为?是因为字符编码似乎更改为UTF-8。
Because it is a French website, there are many accented letters. I'm using the ISO-8859-15 charset for that very reason. However, in the response to my AJAX request, the accents are becoming ?'s because the character encoding seems to be changed back to UTF-8.
如何避免这个?我已经尝试在请求的文档顶部添加一些PHP来设置字符集:
How do I avoid this? I've already tried adding some PHP at the top of the requested documents to set the character set:
<?php header('Content-Type: text/html; charset=ISO-8859-15'); ?>
但是这似乎也不行。任何想法?
But that doesn't seem to work either. Any thoughts?
此外,虽然任何人都在这里...为什么最右边的列似乎变得更小,当一个新的页面加载,在< td>
中每个< li>
包裹到下一行?
Also, while any of you are looking here...why does the rightmost column seem to become smaller when a new page is loaded, causing the table to distort and each <li>
within the <td>
to wrap to the next line?
干杯
推荐答案
UTF-8应该处理所有的口音和外来字符 - 为什么不在你的数据源上使用它?
UTF-8 is supposed to handle all accents and foreign chars - why not use it on your data source?
编辑
[存档测试文件的副本。]与您的数据
一切都应该是UTF-8的第一位。我加载的文件在notepad ++,转换为utf-8和手动更改字符需要的口音。一旦完成一切的工作就像一个魅力。
Everything should be UTF-8 in the first place. I loaded the files in notepad++, converted to utf-8 and manually changed the charactes to accents were needed. Once done everything's working like a charm.
BTW,除非你的服务器被定义为php处理.html文件,你加载的ajax的文件没有得到你的iso字符集。如果你坚持使用iso字符集,请求一个php文件而不是一个html文件,并在头文件(而不是文件本身)中定义字符集
BTW, unless your server is defined to php-process .html files, the files you're loading with ajax aren't getting your iso charset. If you insist on using the iso charset, request a php file instead of an html file, and define the charset in the header (not in the file itself)
这篇关于jQuery AJAX字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!