Reputation: 1172
Posting non-latin based languages with ajax + jquery doesn't save to mysql the correct text.
What I have done is this:
I am using the following jquery code:
I am able to see the translated text sent to the save_translation.php page
var d = {"english":"<?php echo $w;?>","addwords":translated};
data = jQuery.param(d);
$.ajax({
type:"POST",
data:data,
url:"save_translation.php"
});
Each field is set to utf8_general_ci
Ajax post
english:thank you addwords:baie dankie|falemnderit|شكرا|дзякуй|благодаря|gràcies|谢谢|谢谢|謝謝|hvala vam|děkuji|tak|dank u|thank you|tänan teid|salamat|kiitos|merci|grazas|Danke|σας ευχαριστώ|תודה|धन्यवाद|köszönöm|þakka þér|terima kasih|go raibh maith agat|grazie|ありがとう|감사합니다|paldies|ačiū|Ви благодарам|terima kasih|nirringrazzjak|takk skal du ha|تشکر از شما|dziękuję|obrigado|mulţumesc|спасибо|хвала|ďakujem|hvala|gracias|asante|tack|salamat|คุณขอบคุณ|teşekkür ederim|спасибі|cảm ơn bạn|ddiolch 'ch|אַ דאַנק
Server Side ouput
english : thank you
baie dankie|falemnderit|شكرا|дзякуй|благодаря|gràcies|谢谢|谢谢|謝謝|hvala vam|děkuji|tak|dank u|thank you|tänan teid|salamat|kiitos|merci|grazas|Danke|σας ευχαριστώ|תודה|धन्यवाद|köszönöm|þakka þér|terima kasih|go raibh maith agat|grazie|ありがとう|감사합니다|paldies|ačiū|Ви благодарам|terima kasih|nirringrazzjak|takk skal du ha|تشکر از شما|dziękuję|obrigado|mulţumesc|спасибо|хвала|ďakujem|hvala|gracias|asante|tack|salamat|คุณขอบคุณ|teşekkür ederim|спасибі|cảm ơn bạn|ddiolch 'ch|אַ דאַנק|
Each field is set to utf8_general_ci
PhpMyAdmin
thank you|baie dankie|falemnderit|شكرا|дзÑкуй|благодарÑ|grà cies|谢谢|谢谢|è¬è¬|hvala vam|dÄ›kuji|tak|dank u|thank you|tänan teid|salamat|kiitos|merci|grazas|Danke|σας ευχαÏιστώ|תודה|धनà¥à¤¯à¤µà¤¾à¤¦|köszönöm|þakka þér|terima kasih|go raibh maith agat|grazie|ã‚ã‚ŠãŒã¨ã†|ê°ì‚¬í•©ë‹ˆë‹¤|paldies|aÄiÅ«|Ви благодарам|terima kasih|nirringrazzjak|takk skal du ha|تشکر از شما|dziÄ™kujÄ™|obrigado|mulÅ£umesc|ÑпаÑибо|хвала|Äakujem|hvala|gracias|asante|tack|salamat|คุณขภบคุณ|teÅŸekkür ederim|ÑпаÑибі|cảm Æ¡n bạn|ddiolch 'ch|×Ö· ד×Ö·× ×§
Upvotes: 0
Views: 891
Reputation: 222017
Probably it will be enough to use JavaScript function encodeURIComponent
.
If you don't add parameters manual to the URL like myUrl + '?param1=' + param1 + '¶m2' + param2
, but use construction myUrl + '?' + jQuery.param({param1:param1, param2:param2})
then encoding with respect of the function function encodeURIComponent
will make jQuery for you. In the case all '&' characters and 'paramX=' strings will be also added for you.
But the best way to use data
parameter of the jQuery.ajax
method. If you use
jQuery.ajax({
url: myUrl,
data: {param1:param1, param2:param2},
//...
});
then your URL will be appended with '?param1=' + param1 + '¶m2' + param2
with the corresponding encoding full from jQuery
.
If my tips not helps you, please post your code example.
UPDATED: After you posted test data it was clear, that you have no problem with ajax
request. You show that the data of the server look like absolutely correct. So your problem is somewhere between PHP and MYSQL. I works with no from this two products and can now not really help you. Probably information from the following link could help you string issue of utf-8 encoding with PHP and MySQL?. You can try also
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
I wish you much success and quick solving of your problem. Regards
P.S. In your ajax
request you can directly use data: {"english":"<?php echo $w;?>","addwords":translated}
. The call jQuery.param will make jQquery for you because the type of data
is not a string. But it's absolutely independ on your problems.
Upvotes: 1