Reputation: 35
I need to be able to display the letter "é", using $.ajax and a JSON file, but the closest that I get was an alert window saying "�", basically anything will help, just no PHP guys, and yes I have the <meta charset="utf-8">
. Anyways, here's the JavaScript/jQuery code:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "alejandra.json",
contentType: "charset=utf-8; application/json",
dataType: "json",
success: function(data) {
var x = data[0].texto;
alert(x);
}
});
});
And here's the JSON file:
[
{
"texto":"é"
}
]
PS: This is all running locally in my PC.
Upvotes: 1
Views: 872
Reputation: 1
in a very quick test I just performed:
content type charset=utf-8;application/json
(incorrect) is not the same as content type application/json;charset=utf-8
(correct)
the above doesn't make any difference actually, my testing was on what content type the server sent (which does make a difference in some cases)
make sure the .json file is saved UTF-8 encoded - I originally saved it as ansi and it didn't work, but saved in UTF-8 works fine
Upvotes: 1
Reputation: 4218
This Solved the OP's Question
Right click on your file and open it with notepad, click on File
-> Save as
, change encoding to UTF-8
if it's not
Upvotes: 3
Reputation: 74738
May be you need .toLocaleLowerCase()
method:
success: function(data) {
var x = data[0].texto.toLocaleLowerCase();
alert(x);
}
Description
The toLocaleLowerCase() method returns the value of the string converted to lower case according to any locale-specific case mappings. toLocaleLowerCase() does not affect the value of the string itself. In most cases, this will produce the same result as toLowerCase(), but for some locales, such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may be a different result.
Upvotes: 0