Okay, so here is the problem:
I have a form on my php page. When a user has entered a name a presses submit a jQuery click event (on the submit button) collects then information and passes them on through $.ajax().
$.ajax({
url: "ajax/addGatheringSignup.php",
type: "POST",
async: true,
dataType: 'json',
data: {
"id": $_GET['id'],
"name": $signupNameInput.val()
},
success: function(jsonData){
if(jsonData[0].feedback == "ok"){
$signupForm = $('#singupform');
$signupForm.html('Signup successful!');
}else{
Alert(jsonData[0].feedback);
}
},
error: function(){
Alert("error alert");
}
});
As you can see the "name" field is the value from the name inputfield. But when i submit this to my php page (where I don't format anything within the text) its totally garbage in my MySql database. At the moment im trying to get the danish letters æ, ø and å to work.
Atm i know my mysql database are using UTF-8 and my meta-header for my index.php looks like this (every page is generated from the index.php page... ex index.php?page=random):
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
But nothings works. When i post: "æÆ-øØ-åÅ" to the database it saves as: "æÆ-øØ-åÅ". anyone know what i have to do?
EDIT 1:
I can see that on a successful ajax submit the html i set $signupForm to (line 13. in the code above) displays wrong as well (it's normally some danish words where I write the danish chars mentioned)
EDIT 2 (found one solution):
I found a way. $.ajax() according to the jQuery doc, always parses data as UTF8. I don't know why this messed up my code, but when i added *utf8_decode($name)* to the add-function it parsed correct (so i guess my charset must have been set to ISO-8859-1 hidden somehow?). This just made it easier since i could then turn my old charset ISO-8859-1 back on again and remove all my utf8_encode() functions.
My last problem was the one presentated in "EDIT 1". Here i found a solution on how to convert UTF8 strings (again because of $.ajax()):
function decode_utf8( s ){
return decodeURIComponent( escape( s ) );
}