CGI::Application::Plugin::DetectAjax - check for XMLHttpRequest in CGI::Application based modules
package My::App; use base qw/CGI::Application/; use CGI::Application::Plugin::DetectAjax; ... sub myrunmode { my $self = shift; my $object = MyClass->new; my $result = $object->do_work(); if ($self->is_ajax) { return to_json($result); } else { my $t = $self->load_tmpl('myrunmode.tmpl'); $t->param(RESULT => $result); return $t->output; } }
CGI::Application::Plugin::DetectAjax adds is_ajax method to your CGI::Application modules which detects whether the current request was made by XMLHttpRequest.
This method will return true if the current request was made by XMLHttpRequest and false otherwise. It works by checking for 'X-Requested-With' header and its value.
Please report any bugs or feature requests to bug-cgi-application-plugin-ajax@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-cgi-application-plugin-ajax@rt.cpan.org
CGI::Application, CGI, perl(1)
Jiří Pavlovský <jira@getnet.cz>
Copyright (C) 2010 Jiří Pavlovský <jira@getnet.cz>
This library is free software. You can modify and or distribute it under the same terms as Perl itself.
To install CGI::Application::Plugin::DetectAjax, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Application::Plugin::DetectAjax
CPAN shell
perl -MCPAN -e shell install CGI::Application::Plugin::DetectAjax
For more information on module installation, please visit the detailed CPAN module installation guide.