Dancer2::Plugin::Ajax(3pm)

Dancer2::Plugin::Ajax3pm

A plugin for adding ajax route handlers

Usage

    package MyWebApp;
    use Dancer2;
    use Dancer2::Plugin::Ajax;
    # For GET / POST
    ajax '/check_for_update' => sub {
        my $self = shift;
        # ... some Ajax code
    };
    # For all valid HTTP methods
    ajax ['get', 'post', ... ] => '/check_for_more' => sub {
        my $self = shift;
        # ... some Ajax code
    };
    dance;

Version

version 0.400000

Overview

The "ajax" keyword which is exported by this plugin allows you to define a route handler optimized for Ajax queries.

The route handler code will be compiled to behave like the following:

•

Pass if the request header X-Requested-With doesn't equal XMLHttpRequest

•

Disable the layout

•

The action built matches POST / GET requests by default. This can be extended by passing it an ArrayRef of allowed HTTP methods.

The route handler gets the Dancer $self object passed in, just like any other Dancer2 route handler. You can use this to inspect the request data.

    ajax '/check_for_update' => sub {
        my $self = shift;
        
        my $method = $self->app->request->method;
        # ...
    }

Configuration

By default the plugin will use a content-type of 'text/xml', but this can be overridden with the plugin setting "content_type".

Here is an example to use JSON:

  plugins:
    Ajax:
      content_type: 'application/json'

Releases

5 releases since Debian 8 (Jessie); the text changed 3 times.

  1. 8
  2. 10
  3. 11
  4. 12–13

Author

Dancer Core Developers

From libdancer2-plugin-ajax-perl 0.400000-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.