NAME

CGI::Application::Plugin::DetectAjax - check for XMLHttpRequest in CGI::Application based modules

SYNOPSIS

package My::App;

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;

  }
}

DESCRIPTION

CGI::Application::Plugin::LogDispatch adds is_ajax method to your CGI::Application modules which detects whether the current request was made by XMLHttpRequest.

METHODS

is_ajax

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.

BUGS

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.

SEE ALSO

CGI::Application, CGI, perl(1)

AUTHOR

Jiří Pavlovský <jira@getnet.cz>

LICENSE

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.