perl_help26 has asked for the wisdom of the Perl Monks concerning the following question:

Hello I am starting to learn more about perl in Dancer. I have a trivial question about javascript. Not sure what I am doing wrong so this is the code. It's not alerting. In views/index.tt :

<script type="text/javascript"> $(document).ready(function(){ $.get("/", function() { alert ('ALERTING'); }); }); </script> <div id='about-content'>Test Div</div>

In test.pl:

use Dancer; use strict; use warnings; use Dancer ':syntax'; use Dancer::Plugin::Ajax; our $VERSION = "1.0"; set serializer => 'JSON'; set template => 'template_toolkit'; get '/'=>sub{ template 'index'; }; dance;

Thanks!

Replies are listed 'Best First'.
Re: using javascript for dancer perl app
by tobyink (Canon) on Jan 24, 2014 at 14:09 UTC

    Have you checked your browser's Javascript error console?

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

      Thank you so much for the tip... It was a small syntax error! :)

        Depends on your browser. In Opera, it's Ctrl+Shift+O. In Firefox, it's Ctrl+Shift+K. In other browsers it's likely to be something else.

        The console will tell you about various things like Javascript syntax errors.

        use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: using javascript for dancer perl app
by soonix (Chancellor) on Jan 24, 2014 at 16:13 UTC
    since you are "starting" with Dancer: Did you check whether it is set up correctly, e.g. does your "Test Div" render, and are changes there reflected in your browser's output?