Home › Forums › JavaScript › Javascript/jquery messes up special characters
- This topic is empty.
-
AuthorPosts
-
December 4, 2011 at 1:15 am #35449
lulli240
MemberI’m trying to send a string to a php file but when the strings get there all special characters (I’m from Iceland and need characters like þ, æ, ö, ó…) looks like þ æ ö. Help would be appreciated.
The code:
javascript/jquery:
$(document).ready(function(){
//If user submits the form
$("#submitmsg").click(function(){
var clientmsg = $("#usermsg").val();
$.post("post.php", {text: clientmsg});
$("#usermsg").attr("value", "");
return false;
});
});post.php:
require("_config.php");
$address = $_SERVER;
$message = $_POST;
$mem_id = $_COOKIE;
$ip = $address;
$result = mysql_query( "Insert Into chat (user_id, message, ip) Values('$mem_id', '$message', '$ip')",$conn )
or die("Something went wrong while inserting message into database !". mysql_error());
?>December 4, 2011 at 8:34 am #91821Mottie
MemberHi Lulli240!
Make sure the page has the charset as the generated page. In HTML5, it’s a meta tag in the header (more info here):
“utf-8” is just one character set “ISO-8859-1” is the standard for western European character sets (I’m not sure if that includes characters for Iceland).
December 4, 2011 at 12:08 pm #91826lulli240
MemberI have the meta tags on both the pages. The javascript messes the string up but I managed to solve it like this.
$(document).ready(function(){
//If user submits the form
$("#submitmsg").click(function(){
var clientmsg = $("#usermsg").val();
var e_clientmsg = escape(clientmsg); //escape the string
$.post("post.php", {text: e_clientmsg});
$("#usermsg").attr("value", "");
return false;
});
});require("_config.php");
$address = $_SERVER;
$err = array();
$message = urldecode($_POST); // Decode the string
$mem_id = $_COOKIE;
$ip = $address;
$result = mysql_query( "Insert Into chat (user_id, message, ip) Values('$mem_id', '$message', '$ip')",$conn )
or die("Something went wrong while inserting message into database !". mysql_error());
?>And now all my Icelandic characters shows up fine.
Thanks for your answer though Mottie ;)
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.