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 ?
AJAX = Asynchronous JavaScript and XML. In short; AJAX is about loading data in the background and display it on the webpage, without reloading the whole page. Examples of applications using AJAX: Gmail, Google Maps, Youtube, and Facebook tabs. You can learn more about AJAX in our AJAX tutorial.
The jQuery ajax contenttype option is a built-in option that is passed to the ajax() function in the jQuery. The contenttype option is also called as MIME (multipurpose internet mail extension) type, it includes an HTTP header that specifies the information about what kind of data we are sending to the server.
I resolve it in PHP with the following line:
foreach($_POST as $key => $value) {
$_POST[$key] = utf8_decode($value);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With