Chartset encoding when using Ajax ? JQuery
ajax, character-encoding, jquery
Solution
I resolve it in PHP with the following line:
foreach($_POST as $key => $value) {
$_POST[$key] = utf8_decode($value);
}
Problem
I have a web application (UTF-8) in which the following one can be used to send to the server side ``` áéíóú àèìòù ÀÈÌÒÙ ÁÉÍÓÚ ``` Ok. I use something like as follows to send data ``` // Notice $("#myForm").serialize() $.get("/path?", $("#myForm").serialize(), function(response) { }); ``` When i see my recordSet, i get (database charSet encoding is UTF-8) ``` áéÃóú à èìòù ÃÉÃÓÚ ÀÈÌÒÙ ``` Even when using $.post, i get the same result set After seeing serialize() method in JQuery in Action book: Creates a properly formatted and encoded query string from all successful form elements in the wrapped set But, as shown above, it does not appear to work fine. So instead of serialize() method, i use ``` var objectArray = $("#myForm").serializeArray(); var queryString = ""; for(var i = 0; i < objectArray.length; i++) { queryString += "&" + objectArray[i]["name"] + "=" + objectArray[i]["value"]; } $.get("/path?" + queryString, null, function(response) { }); ``` Now i get in database ``` áéíóú àèìòù ÀÈÌÒÙ ÁÉÍÓÚ ``` So Am i missing something when using serialize() method ? Why serialize() method does not work as expected ?