character encoding problem - cross-domain scripting

I have an Asp.Net web app which users include a script tag in their web page, and get data from my server (using JsonP & a Generic handler (ashx))

The data is in hebrew, and I set the charset to utf-8 in the response.

When the client web site (which displays the data) uses "windows-1255" I don't see the text properly.

The script can be included in any web page with any character set.

Do I need to convert my data or set the response charset property differently?

Thanks Yaron


ANSWERS:


When the client web site (which displays the data) uses "windows-1255" I don't see the text properly.

Yeah. Here's the thing: when you are serving <script>, you can set the ‘charset’ parameter in the response's Content-Type to anything you like, but IE will ignore you and use the encoding of the origin page instead. (Maybe some other browsers too.)

So if you're doing JSONP or another script-tag-based means of pulling in data, that data must be either in the same encoding as the origin page, or plain ASCII. If you are providing an external service for many web pages in potentially different encodings, you must stick to ASCII.

That means your JSON encoder must convert all non-ASCII characters in string literals to their JS-escaped form, for example \u20AC instead of a raw €.


Its probably better that you specify clearly to your clients that your interface uses UTF-8 encoding. When they forward your data down to their clients they should set the Response.CharSet to UTF-8. Of course you are alreadying doing that on your end right?



 MORE:


 ? Characters and symbols in HTML
 ? How to pass Unicode characters as JSP/Servlet request.getParameter?
 ? How to pass Unicode characters as JSP/Servlet request.getParameter?
 ? How to pass Unicode characters as JSP/Servlet request.getParameter?
 ? Passing request parameters as UTF-8 encoded strings
 ? HttpServletRequest UTF-8 Encoding
 ? Why the character is corrupted when use request.getParameter() in java?
 ? How to enable reading non-ascii characters in Servlets
 ? encodeURIComponent using ISO-8859-1 encoding for a javascript string
 ? Passing special Characters from JSP to Controller