Amon2でJSONPを使うとき
マニュアルどおりなんですが
http://amon.64p.org/output.html#json
具体的には
app.psgi
enable 'Plack::Middleware::JSONP';
Web.pm
__PACKAGE__->load_plugins(
...,
'Web::JSON',
);
Web/Dispatcher.pm
any '/' => sub { my ($c) = @_; my $data = Hogehoge->get_data($c); if (defined $c->req->param('type') && $c->req->param('type') eq 'json'){ return $c->render_json($data); } else { return $c->render('index.tt' => {data => $data}); } };
js(jquery)
$.ajax({ type: 'GET', url: 'http://www.example.net/?type=json&callback=?', dataType: 'jsonp', success: ... });
あと
render_jsonに渡すのはUTF8フラグをつけてから
perlのJSONの注意点
http://www.donzoko.net/cgi-bin/tdiary/20100406.html#p01
http://search.cpan.org/dist/JSON/lib/JSON.pm#HOW_DO_I_DECODE_A_DATA_FROM_OUTER_AND_ENCODE_TO_OUTER