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.
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>
The actual AJAX works like a charm. My problem lies with the response to the request.
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.
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?
Cheers
I tried many suggestions to read in a textfile with German special characters (ä,ö,ü). In the end:
let me read in the special characters, but only AFTER I explicitly saved FileName.txt in the UTF-8 format. The standard format for saving text files in the Windows Editor is ANSI and not UTF-8, but it can be changed if you "Save as" and use the dropbox next to the Save-Button or use a better Editor to start with.
I´ve had the same problem with pages that:
To solve the problem (using php), I used
utf8_encode()
orhtmlentities()
on the source data. Both worked, I have used them in different projects.I had similar problem. I have text file with json data that has French text. There was always issue displaying some characters. In my case, JavaScript program uses Ajax to retrieve the json text file as follows:
The returned data always had incorrect accented French letters.
The json text looks as follows:
Note in the above sample data, the 3rd element, I placed the text with the correct
é
and incorrectê
French accented letters.For your information, it seemed that there is some global configuration of Eclipse project using
ISO-8859-1
character encoding. In your case it might be different encoding.After checking the solutions above and playing around with the the project, this is what solved my problem:
ISO-8859-1
Now, in my case, I didn't specify any encoding options in the Ajax call and it works fine. Also, if I change the encoding of the text file with json data, it would still work fine.
Tarek
I have faced same problem and tried several ways. And i found the solution. If you set request header for "Accept" like below;
you will see that all the characters seems correct
I have been fiddling around with this problem and found out that this solution works for Firefox and safari (yes, im on a mac at the moment).
when getting the request, i made a content-type=iso-8859-1 here:
Please tell me if someone finds out this doesn't work in ie.
If the whole application is using ISO-8859-1, you can modify your jquery.js replacing all occurences of
encodeURIComponent
byescape
(there are 2 occurrences to replace in the current jquery script - 1.5.1)See encodeUIComponent and escape for more information