jQuery AJAX 字符编码 [英] jQuery AJAX Character Encoding

查看:28
本文介绍了jQuery AJAX 字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个法语网站.有一个时间表页面,侧面的链接可用于加载另一天的时间表.

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 请求时,重音符号变成了 ?'s,因为字符编码似乎改回 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?

此外,当你们中的任何人都在看这里时...为什么在加载新页面时最右边的列似乎变小了,导致表格扭曲并且每个

  • 换行到下一行?

    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.我在记事本++中加载文件,转换为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-process .html 文件,否则您使用 ajax 加载的文件不会获得您的 iso 字符集.如果你坚持使用iso字符集,请求一个php文件而不是一个html文件,并在header中定义字符集(而不是文件本身)

    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屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆