[Catalyst] UTF-8 and Catalyst::Action::Serialize::JSONP

James Spath jspath at pangeamedia.com
Tue Mar 1 16:55:23 GMT 2011


We were having some problems with UTF-8 output via
Catalyst::Action::Serialize::JSONP which Catalyst::Controller::REST
uses for JSONP output.  Basically, unicode data was not being read
correctly by browsers when read via JSONP, whereas it was fine as
JSON.

A solution that worked for us was to edit
Catalyst::Action::Serialize::JSONP and add "; charset=utf-8" to the
content type header:

$c->res->content_type('text/javascript; charset=utf-8');

My guess is that browsers treat text/javascript content differently
than application/json content and require the addition of the charset
to the content-type to read it correctly.

Does this seems like a reasonable solution to our problem?  Is there a
better way?

Thanks!
Jim



More information about the Catalyst mailing list