Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Javascript/jquery messes up special characters

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #35449
    lulli240
    Member

    I’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());
    ?>
    #91821
    Mottie
    Member

    Hi 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).

    #91826
    lulli240
    Member

    I 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 ;)

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.