-1

Is it possible to embed Javascript into HTML: Mason for Perl?

Thank you

<%init>
#do some perl code here

<script type="text/javascript">

//call some javascript function here

</script>
 #do some perl code here

</%init>

I have a web service exposed using JSON and I want to call it using Javascript code.

Can I put the Javascript code between <%perl>?

jas7
  • 2,893
  • 6
  • 23
  • 36
  • 1
    My reading of the manual suggests that `<%init>` is for Perl that should execute before anything else. I don't know why you would put JavaScript in there. JavaScript is content that needs to be output to the browser. – Quentin Oct 24 '13 at 23:10
  • You can't put it in the `<%init>` section, because that's not what `<%init>` does. What are you trying to do? – friedo Oct 24 '13 at 23:29
  • I have a web service exposed using JSON and I want to call it using Javascript code. – jas7 Oct 25 '13 at 00:05
  • Can I put the Javascript code between <%perl>%perl>? – jas7 Oct 25 '13 at 00:47
  • Only if you were going to echo it out but why would … oh, I think I see… – Quentin Oct 25 '13 at 09:19
  • possible duplicate of [Reference: Why does the PHP (or other server side) code in my Javascript not work?](http://stackoverflow.com/questions/13840429/reference-why-does-the-php-or-other-server-side-code-in-my-javascript-not-wor) – Quentin Oct 25 '13 at 09:19

1 Answers1

1

Yes. Just put it in there.

HTML::Mason is designed to let you write ordinary HTML (including stylesheets, JavaScript, and anything else that's valid in a HTML document) while also allowing you to embed Perl code.

PP.
  • 10,764
  • 7
  • 45
  • 59
  • Can I do this in Mason? <%init> #do some perl code here %init> – jas7 Oct 24 '13 at 23:08
  • 1
    Ah if you're trying to execute JavaScript on the server side then you're either wanting Node.JS or you're very, very, very, very, very confused about web browsers and web servers. – PP. Oct 24 '13 at 23:40
  • I have a web service exposed using JSON and I want to call it using Javascript code. – jas7 Oct 25 '13 at 00:05