I'm new to Catalyst and Perl - but my issue is I have a button on the Catalyst "tt" file that I'd like to display the value stored in the stash. Upon a click, the Perl controller file would change the value via an ajax call. However, this just isn't working for some reason. I'm wondering if Catalyst isn't resetting the value in the stash without doing a "refresh" of the page?

I can use the getElementsById and have the text change - but like to let the controller hand that.

Here is the button from the file.tt

<input type="button" class="btn btn-primary btn-block" id="code_button" href="#" onClick="get_codes();" value="[% Catalyst.stash.button_description %]"></input>

This is the Javascript function to do the ajax call:

    function get_codes() {
       jQuery.ajax({
          async: false,
          type: 'POST',
          url: '/grl/get_codes',
          dataType: 'json',
          success: function( data ) {
             console.log(data);
             document.getElementById("grl_button").value="New Value"; <--- Works of course
             document.getElementById("grl_button").value="[% Catalyst.stash.button_description %]"; <--- this doesn't update to new value set in the controller
             console.log(document.getElementById("code_button").value);
          }
       });
    };

This is the code from the Perl controller:

 sub get_codes : PathPart('get_codes') Chained('grl') Args(0) {
    my ( $self, $c ) = @_;
    $DB::single=1;

    my $button_description = "Another Value";
    $c->stash->{button_description} = $button_description;
    my $ret = {error=>0,message=>"Success?"};
    $c->res->body(encode_json($ret));
    $c->detach;
 }

I expect that the click on the button would actually have the text of the button change to "Another Value" but instead it remains the same.

0 Answers