jQuery: AJAX umlauts & special characters are a mess
Posted
by rayne
on Stack Overflow
See other posts from Stack Overflow
or by rayne
Published on 2010-03-29T15:22:59Z
Indexed on
2010/03/29
15:33 UTC
Read the original article
Hit count: 840
I've just created my first ajax function with jQuery which actually works, but unfortunately the character encoding (for characters like ä, ö, ü, ß, c, c, å, ø) is a nightmare.
My files and my database are all UTF-8. I've tried a multitude of options in the ajax function and the PHP function, none of which were satisfactory.
This is my ajax
var dataString = {
'name': name,
'mail': mail
// other stuff
}
$.ajax({
type: "POST",
url: "/post.php",
data: dataString,
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
cache: false,
success: function(html){
// do stuff
}
I've tried it without contentType: "application/x-www-form-urlencoded;charset=UTF-8" and I've tried to wrap the affected data in encodeURIComponent(), none of which worked.
When I use that AJAX with htmlentities() in my php, my umlauts look like this in plain text: UE �, AE �, OE �, ue ü, ae ä, oe o
And like this in the database: UE Ü , AE Ä, OE Ö, ue ü, ae ä, oe o
If I don't use htmlentities() but mysql_real_escape_string() instead (or neither), they look good in plain text, but they look like this in the database: AE Ä, OE Ö, UE Ü, ae ä oe ö ue ü
I've been trying tons of options for hours now, but I can't find a solution that works. So far the only option I seem to have is having them look like a total mess in the database, but that would be very contraproductive if those data sets need to be edited.
© Stack Overflow or respective owner