The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojolicious::Plugin::ISAjax - XMLHttpRequest Detection Plugin

SYNOPSIS

  # Mojolicious
  $self->plugin('ISAjax');

  # Mojolicious::Lite
  plugin 'ISAjax';

  # Example of usage in a template
  % if ( isajax ) {
  % layout 'ajax';
  % } else {
  % layout 'default';
  % }

  # Example of usage in a controller
  return $self->render(template => 'foo/ajax') if $self->isajax;

DESCRIPTION

Distinguish between normal requests and Ajax requests by checking XMLHttpRequest string in X-Request-With header and set stash value for isajax accordingly.

Also exports isajax helper.

Mojolicious::Plugin::ISAjax is a Mojolicious plugin.

OPTIONS

stash

  # Mojolicious
  $self->plugin('ISAjax' => {stash => 'ajax'});

  # Mojolicious::Lite
  plugin 'ISAjax' => {stash => 'ajax'};

Stash name for Ajax flag, defaults to isajax.

HELPERS

isajax

  % if ( isajax ) {
  <h1>Hello from Ajax Request</h1>
  % }

  $self->isajax;

Returns 1 in case of an Ajax request. Otherwise returns undef.

METHODS

Mojolicious::Plugin::ISAjax inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  $plugin->register;

Register plugin in Mojolicious application.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.