18 Jan
2011
18 Jan
'11
10:22 a.m.
On 18/01/11 1:05 PM, Puneet Kishor wrote:
As the subject line says, I would like to use a template to create a JSON structure that I would like to send back to the browser in response to an ajax request. Is that possible?
Hi Puneet, I believe so, the following code snippet works for me. sub json { return 'application/json'; } get '/testjson' => sub { content_type json; return template 'json.tt', { r => { id => 1, name => "Widgets Co."} }, { layout => undef }; }; Where json.tt is { "name": "<% r.name %>", "id":<% r.id %> } Cheers Matt