Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How do I mix up Perl and jQuery (for beginners)

by daxim (Curate)
on Aug 21, 2013 at 14:02 UTC ( [id://1050354]=note: print w/replies, xml ) Need Help??


in reply to How do I mix up Perl and jQuery (for beginners)

I'm making some assumptions here. Your confusion stems probably from the fact that you have little idea how the Web works on the HTTP message level. Read a book or two about modern Web development, the concepts should transfer easily to your tools of choice. Following is a very small PSGI application to get you started. The application-specific JavaScript can also be put into a stand-alone file. Yes, a templating system is a good idea. So is using a Web framework, which is a small step up from printing out HTML piecewise.
my $app = sub { return [200, ['Content-Type' => 'application/xhtml+xml'], [<<'END_ +HTML']]; <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="http://code.jquery.com/jquery-2.0.3.min.js"></scr +ipt> <script> jQuery(document).ready(function(){ jQuery('p').append(' Hello world from jQuery!'); }); </script> </head> <body> <p>Greetings.</p> </body> </html> END_HTML };

edit: JS does not need to be in the HTML

Replies are listed 'Best First'.
Re^2: How do I mix up Perl and jQuery (for beginners)
by eyekona (Acolyte) on Aug 21, 2013 at 14:27 UTC

    You are right i have no idea how old or modern web applications work and i just know the theory about http and html i learned in university some years ago...

    I would love to read a book or two and learn perl, html and jquery properly but my boss wants to see some results on monday also i told him i have no idea of web programming and never done something like this before...

    I'm not asking you to do my work just asking for the simplest of an example you can give me to have something to beginn with.

    I already wrote some thousand lines of code and to my own surprise it works - it just doesn't look the way he wants it to - and now he forces me to use this jquery stuff so for example he don't want to type a name, he searches the data for, but else select one from a drop-down box which gets the names from the db - and i have no idea how to do that...

    I really appreciate your help. Thank you.

      It sounds like you need to spend time reading up on jQuery and AJAX. Your description reads like your boss wants you to use jQuery and AJAX to query a database, via server side Perl. Perhaps he saw your "some thousand lines of code" and doesn't think it's going to be maintainable. jQuery does a lot of heavy lifting for you, it's a widely used framework. If you were concerned by this requirement I suspect you'd have asked your boss about this already. Using Perl, jQuery, and JSON for Web development should be of interest.

      Update: added a few words to second sentance.

        Thank you very much for posting this example - i will go through it and look if i can get it working and if i understand what it does. :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 10:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found