ajax plugin strangeness
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 -->
I've experienced something similar. If I have a Ajaxed request that fails due to a server error, then there is a good chance that the page that the request was made from will, on the next page refresh, l also be treated as though it is an ajax page, i.e. it will lose its headers and footer etc. My guess is that the ajax plug has some global variable that does not get reset after a failed request. Sadly, I've not found a way of consistently reproducing it. I'm on apach2. On Wed, Oct 12, 2011 at 1:57 AM, Puneet Kishor <punk.kish@gmail.com> wrote:
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 -->
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On Wed, Oct 12, 2011 at 9:36 AM, Stephen Fenwick-Paul <stephen@activeg.org>wrote:
My guess is that the ajax plug has some global variable that does not get reset after a failed request. Sadly, I've not found a way of consistently reproducing it.
Once we make the transition to Dancer 2, all plugins will be updated and everything will have completely lexical variables, no global issues of any kind. If this is the problem, it will be solved soon enough. :)
On Oct 12, 2011, at 3:25 AM, sawyer x wrote:
On Wed, Oct 12, 2011 at 9:36 AM, Stephen Fenwick-Paul <stephen@activeg.org>wrote:
My guess is that the ajax plug has some global variable that does not get reset after a failed request. Sadly, I've not found a way of consistently reproducing it.
Once we make the transition to Dancer 2, all plugins will be updated and everything will have completely lexical variables, no global issues of any kind. If this is the problem, it will be solved soon enough. :)
Thanks, however, I have so many apps, I think it will be a long while before I transition to Dancer 2. Look forward to it though. Puneet.
Indeed, dancer2 is goint to kick our asses! All of us ;) And sawyer is right, all the scope-leaks related to globals are no more in dancer2, because... well there is not a single global in the code. 2011/10/12 Puneet Kishor <punk.kish@gmail.com>:
Once we make the transition to Dancer 2, all plugins will be updated and everything will have completely lexical variables, no global issues of any kind. If this is the problem, it will be solved soon enough. :)
Thanks, however, I have so many apps, I think it will be a long while before I transition to Dancer 2. Look forward to it though.
Oh please, could give it a try (in a development environment of course). Because dancer2 is almost finished (85% of Dancer 1 DSL is supported) and I've entered a backward compatibility session. You can grab the last version of dancer2 on github: http://github.com/sukria/dancer2 So I am *very* interested in migration test reports. Thanks!
2011/10/12 sawyer x <xsawyerx@gmail.com>:
Once we make the transition to Dancer 2, all plugins will be updated and everything will have completely lexical variables, no global issues of any kind. If this is the problem, it will be solved soon enough. :) Ok it's be very cool. I have the same problem when a request ajax fail.
-- \0/ Hobbestigrou site web: erakis.im
Looking forward D2, but in the meanwhile, do you know of anything we can do to safely recover from a zombied ajax call - can we manually reset something etc? On 14 October 2011 22:10, Natal Ngétal <hobbestigrou@erakis.im> wrote:
2011/10/12 sawyer x <xsawyerx@gmail.com>:
Once we make the transition to Dancer 2, all plugins will be updated and everything will have completely lexical variables, no global issues of any kind. If this is the problem, it will be solved soon enough. :) Ok it's be very cool. I have the same problem when a request ajax fail.
-- \0/ Hobbestigrou site web: erakis.im _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On Oct 14, 2011, at 4:15 PM, Stephen Fenwick-Paul wrote:
Looking forward D2, but in the meanwhile, do you know of anything we can do to safely recover from a zombied ajax call - can we manually reset something etc?
Fwiw, I removed the Ajax plugin, and also migrated that specific problematic site from Starman to Apache, and the problem seems to have gone away. I haven't done a more scientific analysis of whether it was one or the other causing the issue, so my other sites are still on Starman.
On 14 October 2011 22:10, Natal Ngétal <hobbestigrou@erakis.im> wrote:
2011/10/12 sawyer x <xsawyerx@gmail.com>:
Once we make the transition to Dancer 2, all plugins will be updated and everything will have completely lexical variables, no global issues of any kind. If this is the problem, it will be solved soon enough. :) Ok it's be very cool. I have the same problem when a request ajax fail.
-- \0/ Hobbestigrou site web: erakis.im _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On Oct 12, 2011, at 2:36 AM, Stephen Fenwick-Paul wrote:
I've experienced something similar.
If I have a Ajaxed request that fails due to a server error, then there is a good chance that the page that the request was made from will, on the next page refresh, l also be treated as though it is an ajax page, i.e. it will lose its headers and footer etc.
My guess is that the ajax plug has some global variable that does not get reset after a failed request. Sadly, I've not found a way of consistently reproducing it.
I'm on apache.
Ok, good to know I was not hallucinating. Keep in mind, I was experiencing the strangeness without any server error involved. Just erratically, for exactly the same kind of request (identical headers, just different query params) submitted via the same jQuery method, I would get back a JSON stream (correctly) or a web page (incorrectly). I have gone removed Dancer::Plugin::Ajax now, but as a result, have gone rather verbose to accomplish everything. Here is my pattern, and I seek the communities suggestions on improving it. Assuming I want to get a resource called "foo" I am now implementing two routes (that is, two routes per resource) # when foo is requested as http://server/foo # a complete web page should be returned get '/foo' => sub { my $p1 = params->{'p1'}; my $p2 = params->{'p2'}; .. template "foo", \%options; }; # when foo is requested as an ajax call via http://server/foo.json # only a JSON packet should be returned get '/foo.json' => sub { my $p1 = params->{'p1'}; my $p2 = params->{'p2'}; .. return to_json \%options; }; and, for the "index" page, that is, the page when there is no path_info, assuming foo is the default resource that should be returned, the following additional route is before the above two # when user goes to http://server/ # a complete web page should be returned get '/' => sub { my $p1 = params->{'p1'}; my $p2 = params->{'p2'}; .. template "foo", \%options; }; Is the above the right way or is there a better way?
On Wed, Oct 12, 2011 at 1:57 AM, Puneet Kishor <punk.kish@gmail.com> wrote:
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 -->
participants (5)
-
Alexis Sukrieh -
Natal Ngétal -
Puneet Kishor -
sawyer x -
Stephen Fenwick-Paul