Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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>

In reply to Re^2: Loop function in Javascript fails when combined with perl array ( Mojo::JSON ) by Anonymous Monk
in thread Loop function in Javascript fails when combined with perl array by ash1351

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-05-20 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found