[Dancer-users] cross domain ajax to dancer app

Alex Kalderimis alex at flymine.org
Tue Jul 12 23:50:55 CEST 2011

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. 


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

	        "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;

	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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110712/b940e6aa/attachment.htm>

More information about the Dancer-users mailing list