18 Jan
2011
18 Jan
'11
3:13 p.m.
Matthew Vickers wrote:
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 %> }
Oh! Brilliant! That is exactly what I was looking for. I am going to try it out and report back. Many thanks, Puneet.