[Dancer-users] cross domain ajax to dancer app

franck franck at lumberjaph.net
Wed Jul 13 09:37:45 CEST 2011


since you're already using Plack (via Starman) maybe this could help
http://search.cpan.org/dist/Plack/lib/Plack/Middleware/JSONP.pm


On Wed, Jul 13, 2011 at 6:05 AM, Alex Kalderimis <alex at flymine.org> wrote:

> That is exactly right. In this context the server is the whole stack,
> including your webapp, which is solely responsible for getting the content
> right.
>
> Dancer makes writing webapps easier, but it doesn't do everything. Perhaps
> this is a good area for a plugin or some sugar though...
>
>
> Alex
>
> -----
> sent from my phone - please excuse any brevity
>
> ----- Reply message -----
> From: "Mr. Puneet Kishor" <punk.kish at gmail.com>
> To: "Mr. Puneet Kishor" <punk.kish at gmail.com>
> Cc: "Alex Kalderimis" <alex at flymine.org>, "Dancer Users" <
> dancer-users at perldancer.org>
> Subject: [Dancer-users] cross domain ajax to dancer app
> Date: Wed, Jul 13, 2011 4:43 am
>
>
>
>
>
> On Jul 12, 2011, at 10:13 PM, "Mr. Puneet Kishor" <punk.kish at gmail.com>
> wrote:
>
> > On Jul 12, 2011, at 4:50 PM, "Alex Kalderimis" <alex at flymine.org> wrote:
> >
> >> Remember that jsonp requests must return their data wrapped in the
> function callback to work. If not, the json will be evaluated, but do
> nothing, as it is in void context (so to speak). Dancer does not do this for
> you - you will need to read the callback parameter yourself.
>
>
> On more research, I think I understand better what you are suggesting. I
> don't have access to my server ritnow, but I am guessing I would have to do
> something like follows
>
>
> >> get '/poly.:format' => sub {
> >> my $poly = params->{'BBOX'};
>
> get '/poly.:format' => sub {
>    my $poly = params->{'BBOX'};
> + my $callback = params->{'callback'};
>    my $res = recs_within_poly($poly);
> + $res = $callback . '(' . $res . ')';
>    return $res;
> }
>
>
> Does the above make sense?
>
>
>
> >>
> >
> >
> > I kind of follow what you are saying, but I am not sure what I am
> supposed to do. From my side (the client side), I am specifying that it is a
> JSONP request, and I am even specifying the callback param. From what I
> understand, as you state above, the server is supposed to send back the JSON
> stream wrapped in the function callback. Let me read that again -- the
> server is supposed to do the above. Dancer is the responding server, and it
> is not doing so, as you confirm above. So, how do I read the callback param
> myself?
> >
> > I checked Firebug as well as the Safari web developer... The JSON object
> is clealy returned, but the jQuery Ajax call's success method is never
> triggered. Instead, its error method is triggered.
> >
> > Suggestions?
> >
> > Many thanks in advance.
> >
> >
> >> Alex.
> >>
> >> -----
> >> sent from my phone - please excuse any brevity
> >>
> >> ----- Reply message -----
> >> From: "Mr. Puneet Kishor" <punk.kish at gmail.com>
> >> To: "dancer-users" <dancer-users at perldancer.org>
> >> Subject: [Dancer-users] cross domain ajax to dancer app
> >> Date: Tue, Jul 12, 2011 10:30 pm
> >>
> >>
> >> I am trying to send an ajax GET request from one dancer app (powered by
> Starman on one port) to another dancer app (powered by Starman on another
> port). I am using jQuery like so
> >>
> >>   $.ajax({
> >>       "url": url,
> >>       "data": data,
> >>       "type": "GET",
> >>       "dataType": "jsonp",
> >>       "jsonpCallback": function(res) {
> >> .. do something with res ..
> >> }
> >>   });
> >>
> >> I can see the result come back from the second dancer app in Safari web
> inspector. It looks like a JSON stream, but it doesn't trigger the
> jsonpCallback. The web inspector complains that "Resource interpreted as
> script but transferred with MIME type application/json." I am wondering if
> there is something in the second dancer app (the one that returns the
> result) which is setting a wrong header that is causing the callback to not
> be tripped. The code in the second dancer app looks like so
> >>
> >> use Dancer::Plugin::REST;
> >> prepare_serializer_for_format;
> >>
> >> use DBI;
> >>
> >>
> >> get '/poly.:format' => sub {
> >> my $poly = params->{'BBOX'};
> >>
> >>        my $res = recs_within_poly($poly);
> >>        return $res;
> >> };
> >>
> >> By the way, seems like if I use Dancer::Plugin::REST, I can't use
> Dancer::Plugin::Ajax, or can I? Changing the above route to `ajax '../ =>
> sub {};` gives an error that the route was not found.
> >>
> >>
> >> _______________________________________________
> >> Dancer-users mailing list
> >> Dancer-users at perldancer.org
> >> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
>


-- 

franck cuny

http://lumberjaph.net - http://github.com/franckcuny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110713/c5b1302a/attachment.htm>


More information about the Dancer-users mailing list