Question

I have the following code in my main Dancer app .pm:

package Deadlands;
use Dancer ':syntax';
use Dice;

our $VERSION = '0.1';

get '/' => sub {
    my ($dieQty, $dieType, $bonus);
    my $button = param('button');
    $dieQty = param('dieQty');
    $dieType = param('dieType');
    $bonus = param('bonus');
    if (defined $dieQty && defined $dieType) {
        return Dice::Dice->new(dieType => $dieType, dieQty => $dieQty, bonus => $bonus)->getStandardResult();
    }
    template 'index';
};

true;

Here is my JavaScript:

$(document).ready(function() {
     $('#standardRoll').click(function() {
          $.get("/lib/Deadlands.pm", { button: '1', dieType: $("#dieType").val(), dieQty: $("#dieQty").val(), bonus: $("#bonus").val() }, processData);
          function processData(data) {
               $("#result").html(data);
          }
     });
});

I have a div in my web page called result that I want to be updated with the die roll result from Perl. Dancer keeps coming back with a 404 error in the command window when I push the submit button.

Was it helpful?

Solution

/lib/Deadlands.pm needs to be the URL of your route (probably / in this case), not the filesystem path of your Perl module.

OTHER TIPS

Your AJAX request needs to point to a URL that actually exists, not a filename that has nothing to do with the web. Looks like $.get('/', ...) would do in this case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top