Skip to content

Instantly share code, notes, and snippets.

@dynax60
Created September 3, 2010 08:01
Show Gist options
  • Save dynax60/563576 to your computer and use it in GitHub Desktop.
Save dynax60/563576 to your computer and use it in GitHub Desktop.
An example of JSONP service (cross-domain) on Mojolicious..
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/mojo/lib";
use Mojolicious::Lite;
# /test/?foo=bar&callback=smth
get '/test' => sub {
my $self = shift;
my $foo = $self->param('foo') || '';
my $callback = $self->param('callback') || 'jsonp';
...
my $json = $self->render(
json => {
'status' => 'OK',
'result' => 'successful'
},
partial => 1);
$self->render(data => "$callback($json)", format => 'js');
} => 'test';
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment