Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery when appending text to html charset utf8 not working

When I'm passing information to a div inside html the charset utf 8 is not recognized and it comes with interrogation points inside the text. Is there a way to force the charset utf 8 inside jquery so all the text passed by the script comes in the correct charset?

Edit: I think I set all the charsets I could inside all my files: HTML

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type:application/json; charset=UTF-8" />
<script type="text/javascript" src="scripts/jquery-1.9.0.min.js" charset="utf-8"></script>
<script type="text/javascript" src="message_validator.js" charset="utf-8"></script>
</head>
<body>
<div class="error_display" charset="utf-8"></div>
<form charset="utf-8">
<input type="text" id="name" class="textbox" name="name" minlength="2" maxlength="12" />
</form>
</body>

JQUERY

 $(document).ready(function() {
    $(document).load("Content-Type:application/json; charset=UTF-8");
    $('.submit').click(function(){
        var errorlist = [];
        errorlist.length = 0;

        errorlist.push("- Tem de preencher os campos obrigat&#243;rios.");

         if(errorlist.length >= 1){
            $('.error_display').animate({'height':errorlist.length*20}, {queue:false, duration:500});
            for(var i = 0; i < errorlist.length; i++) {
                $('.error_display').append(errorlist[i]+"<br/>");
            }

         }
    });
});
like image 952
CIRCLE Avatar asked Oct 06 '22 04:10

CIRCLE


1 Answers

Put your text with the correct characters and then try to decode it like this:

errorlist.push(decodeURIComponent(escape("- Tem de preencher os campos obrigatórios.")));

Check also those examples to encode/decode the text here

like image 111
Valdemar Avatar answered Oct 13 '22 10:10

Valdemar