Reputation: 4869
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ó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/>");
}
}
});
});
Upvotes: 6
Views: 16198
Reputation: 2543
One thing that one should be aware of, is taht the encoding of the script file itself can result in this error. Make sure that your script file is encoded correctly. In Visual Studio, this is done by:
It varies a bit from IDE to IDE, but the gist is the same
Upvotes: 1
Reputation: 5476
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
Upvotes: 2
Reputation: 6354
This should not be an issue. Make sure your page is set to use UTF8 in the meta tag.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Also make sure the source of this text (if it's server-side, you did not specify in OP) is sending it to you as UTF-8.
Upvotes: 1