views:

29

answers:

1

I want to send a response to a get request made by the javascript object 'XMLHTTPRequest.'

The response content-type will be 'text/plain'.

I would like to add a 'charset' to that (i.e. 'Content-Type:text/plain;charset=UTF-8')

What encodings does javascript work with natively and what encodings will work with javascript on all browsers?

I did find the following site which makes me think that UTF-8 encoding is a safe bet:

http://jerakeen.org/test/unicode/?charset=iso-8859-1

Any other thoughts on this subject? (The server side technology is .NET.)

+1  A: 

Yes, your reply can specify that it is encoded in UTF-8. And it's an excellent choice, too.

All the modern browsers understand UTF-8 natively. And it is preferred over 8859-1 (which is so last-century).

Main thing to watch out for: what is the original html page encoded in? (The page that is sending the XMLHTTPRequest?) Best would be for that page to also be encoded in UTF-8.

If it is something else, then I'm not sure that everything will magically work. I would test in all the browsers if you're not using UTF-8 consistently.

Added:

You can also look at the incoming Ajax request to your server. Its Accept-Charset heading should include utf-8. You can look at the Ajax request using Firebug's "Net" tab or the Fiddler tool. If you're controlling the originating page, then you'd just need to check the charset once in development.

If some other groups in your org are creating pages which then call your Ajax server, you might want to bullet-proof your app by always checking the incoming Accept-Charset headings.

Larry K