Reputation: 6865
I am working on a Javascript project that uses AngularJS. When I get data with http request, all characters are appearing well. For example, a downloaded string with ajax is "räksmörgås", when written to the console as plain text, is appearing with ugly charecters.
console.log("räksmörgås")
results into this: r�ksm�rg�s
Is this a file type encoding problem? Or are JavaScript strings always UTF-16 causing this problem?
Upvotes: 1
Views: 2420
Reputation: 11551
I think the problem is that you are not using the correct charset. For Swedish try to change the character encoding to iso-8859-1
or windows-1252
. I suppose that you are sending the server response without the correct headers and the browser interprets it as UTF-8 as the default charset.
So maybe changing the header charset as below will resolv the issue:
Content-Type: text/plain; charset=windows-1252 // or
Content-Type: text/plain; charset=iso-8859-1
Another solution would be to declare your script tag with charset, this way forcing Js to handle the characters to be interpreted with a specific encoding.
<script src="yourscritp.js" charset="UTF-8"></script>
Upvotes: 1