Dancer...n::Ajax(3pm)

πŸ“¦
version 0.400000 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

Dancer2::Plugin::Ajax(3pm) β€” a plugin for adding Ajax route handlers πŸ’…

okay bestie, so this is the manual page for Dancer2::Plugin::Ajax, straight outta the User Contributed Perl Documentation (the header on this page literally prints it as Dancer...n::Ajax(3pm), iykyk β€” the terminal just clips the long name). It's a Perl plugin, it's giving main character energy, and it's about to make your Ajax routes so much less annoying. πŸ¦‹


✨ VERSION ✨

version 0.400000 πŸŽ€


✨ SYNOPSIS ✨

no cap, this is the whole vibe in one code block:

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;

✨ DESCRIPTION ✨

The ajax keyword, which is exported by this plugin (yes, it just hands you ajax, no extra work πŸ’–), lets you define a route handler that's been optimized for Ajax queries. Obsessed, honestly.

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 (no layout for you, bestie)
  • 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". Literally that easy.

Here is an example to use JSON:

plugins:
  Ajax:
    content_type: 'application/json'

slay. 🌈


✨ AUTHOR ✨

Dancer Core Developers πŸ‘‘


This software is copyright (c) 2016 by Alexis Sukrieh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 🫢


and that's the whole page, bestie! πŸ’œ this one's from perl v5.36.0, dated 2022-12-12, and it lives in the User Contributed Perl Documentation section. go build something iconic with it. periodt. πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from