[Dancer-users] ajax plugin strangeness

Puneet Kishor punk.kish at gmail.com
Wed Oct 12 02:57:51 CEST 2011


Perhaps I don't understand how to correctly use the Dancer::Plugin::Ajax. I am running Dancer 1.3072 with Dancer::Plugin::Ajax running off of Starman proxies behind Apache2. I experience the following strangeness (which, you can test at http://humanesettlements.punkish.org)... Some Ajax queries (sent via jQuery) return as JSON, while others return as full html in spite of having identical headers. My server side code is

	ajax '/' => sub {
		my $page = params->{'page'} || 1;
		my $tags = params->{'tags'};

		my $res = query('page' => $page, 'tags' => $tags);

		return to_json \%res;
	};

	get '/' => sub {
		my $page = params->{'page'} || 1;
		my $tags = params->{'tags'};
	
		my $res = query('page' => $page, 'tags' => $tags);
		template "ideas", \%res;
	};


Here are the queries as captured in the web debugger (in Safari). The following returned JSON

	• Request URL:http://humanesettlements.punkish.org/?tags=old_people
	• Request Method:GET
	• Status Code: 200 OK
	• Request Headers
		• Accept:application/json, text/javascript, */*; q=0.01
		• Referer:http://humanesettlements.punkish.org/
		• User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/534.48.3 
                     (KHTML, like Gecko) Version/5.1 Safari/534.48.3
		• X-Requested-With:XMLHttpRequest
	• Query String Parameters
		• tags:old_people
	• Response Headers
		• Connection:Keep-Alive
		• Content-Length:2905
		• Content-Type:text/xml; charset=utf-8
		• Date:Wed, 12 Oct 2011 00:42:29 GMT
		• Keep-Alive:timeout=5, max=99
		• Server:Perl Dancer 1.3072
		• X-Powered-By:Perl Dancer 1.3072

	JSON response (snipped): {"prev_str":"..}

The following failed in that it returned full HTML content in spite of sending the correct revue headers

	• Request URL:http://humanesettlements.punkish.org/?tags=old_people+implementation
	• Request Method:GET
	• Status Code: 200 OK
	• Request Headersview source
		• Accept:application/json, text/javascript, */*; q=0.01
		• Referer:http://humanesettlements.punkish.org/?tags=old_people
		• User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/534.48.3 
                     (KHTML, like Gecko) Version/5.1 Safari/534.48.3
		• X-Requested-With:XMLHttpRequest
	• Query String Parametersview URL encoded
		• tags:old_people implementation
	• Response Headersview source
		• Connection:Keep-Alive
		• Content-Length:21176
		• Content-Type:text/xml; charset=utf-8
		• Date:Wed, 12 Oct 2011 00:42:37 GMT
		• Keep-Alive:timeout=5, max=100
		• Server:Perl Dancer 1.3072
		• X-Powered-By:Perl Dancer 1.3072

	HTML response (snipped): <!doctype html>

		<!-- 
    		hacked by Puneet Kishor, based on HTML Boilerplate by Paul Irish and Divya Manian
    		all modifications released under a CC0 waiver by Puneet Kishor
    		March 15, 2011
    
    		See http://html5boilerplate.com/ for the original
		-->



More information about the Dancer-users mailing list