Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Loop function in Javascript fails when combined with perl array ( Mojo::JSON )

by Anonymous Monk
on Aug 26, 2015 at 23:50 UTC ( #1140135=note: print w/replies, xml ) Need Help??


in reply to Re: Loop function in Javascript fails when combined with perl array
in thread Loop function in Javascript fails when combined with perl array

Hi friend, Mojo::JSON is core mojo and provides an encode_json , so
#!/usr/bin/perl -- use Mojolicious::Lite; use Mojo::JSON qw/ /; get '/' => sub { my $c = shift; my @array = ( 'hi', [ qw/ ro sham bo /], 'bye', ); $c->stash( vars => \@array ); $c->render( template => 'hello', format => 'html' ); }; app->start; __DATA__ @@ hello.html.ep <script> var headname = <%== Mojo::JSON::encode_json( $vars ) %>; alert( headname[0] ); </script> __END__ no more templates no more books this is how you run it and what you ge +t $ perl mojo-hello-mojo-json.pl get / [Wed Aug 26 16:55:06 2015] [debug] Your secret passphrase needs to be +changed [Wed Aug 26 16:55:06 2015] [debug] GET "/" [Wed Aug 26 16:55:06 2015] [debug] Routing to a callback [Wed Aug 26 16:55:06 2015] [debug] Rendering template "hello.html.ep" +from DATA section [Wed Aug 26 16:55:06 2015] [debug] 200 OK (0.004393s, 227.635/s) <script> var headname = ["hi",["ro","sham","bo"],"bye"]; alert( headname[0] ); </script>
  • Comment on Re^2: Loop function in Javascript fails when combined with perl array ( Mojo::JSON )
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1140135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2019-09-23 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (279 votes). Check out past polls.

    Notices?