[Dancer-users] cross domain ajax to dancer app

Mr. Puneet Kishor punk.kish at gmail.com
Wed Jul 13 05:13:55 CEST 2011

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. 

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.


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

More information about the Dancer-users mailing list