Javascript character set screw-ups (via) Some browsers treat JavaScript files as having the same content-type as the page from which they are linked. This could cause problems with UTF-8 encoded JSON; the workaround is serving up ASCII with unicode escape sequences.
Well, he could add a
charset="utf-8"attribute to the<script>tags. That fixes the issue in all browsers I've ever come across.I don't know about the XMLHTTPRequests (haven't tried) but I bet there's a similar property/method/attribute/thingy that we can use there.
Már - 22nd December 2006 19:43 - #
XMLHttpRequestok. One could argue that Internet Explorer is the browser that's consistent here since browsers generally ignore theContent-Typeheader for script files. Apparently most still look at thecharsetparameter though.Anne van Kesteren - 24th December 2006 18:20 - #
I've updated the web page with this, but I feel that I shouldn't have to know what charset the remote page is in. For those remote JSON APIs that are called by including a <script> tag, you'd need to make the charset of the remote page part of the public API. Not unreasonable, but (a) no-one will do it, and (b) it feel inelegant.
Tom Insam - 26th December 2006 15:46 - #
Oh, I totally agree with you. Just pointing out some facts.
Anne van Kesteren - 26th December 2006 22:18 - #