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:
Here's the JS I'm using to do this:
<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的工作原理就像一个魅力。我的问题在于响应于该请求。
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?
此外,当任你正在寻找在这里...为什么最右边的列似乎变得更小,当一个新的页面被加载,从而导致表歪曲和每个&LT;李&GT;
在&LT; TD&GT;
换到下一行
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?
EDIT
Here's a test file with your data
[Archive copy of the test file.]
一切都应该是UTF-8在首位。我装在记事本+ +中的文件,转换为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.
顺便说一句,除非你的服务器被定义为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屋!