Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.

by msinfo (Sexton)
on Sep 01, 2013 at 21:32 UTC ( #1051864=note: print w/ replies, xml ) Need Help??


in reply to Re^3: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.
in thread CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.

Sorry to all of you, but it's not working. Let me clear myself, I wanna write a CGI script, which would do following.

# required modules use CGI; use CGI::Ajax; # html generation depending upon session info # begining html code if ($session-start) print $cgi->p("user no" . $session->id); else print $cgi->p("guest"); # remaining html code # ajax call my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func); print $pjx->build_html($cgi, \&htm);

I am finding it difficult to generate HTML content with session info, and forward it to Ajax call

If it wouldn't have been Ajax call, then, manipulating HTML content depending upon session info was easy part for me.


Comment on Re^4: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.
Download Code
Re^5: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.
by Anonymous Monk on Sep 02, 2013 at 00:01 UTC
      Hi, Anonymous Monk Thanks for your calm advice and code. Below is code which worked.
      $html .= $cgi->div({-id=>'container'}, $cgi->img({src=>'images/pic.png', height=>'100px', + width=>'150px'}), ( (($session->is_expired) || ($session->is_empty)) ? ($cgi->p("false")) :($cgi->p("true")) + ), $cgi->div( {-id=>'menu_bar'}, # rest of html

      And here is code, which didn't

      $html .= $cgi->div({-id=>'container'}, $cgi->img({src=>'images/pic.png', height=>'100px', + width=>'150px'}), ( (while ($num <=5) {($cgi->p($num)) ($num++)}) ), $cgi->div( {-id=>'menu_bar'},

      What I did wrong in 'while' case. I went through links, provided by you. So here $html .= $cgi->div#rest of code, is one big statement and rest of part on right side are expressions.

      But, could not grasped the concept and structure behind parenthesis well.

      And is it possible to use other Perl blocks in this fashion.?

        Whoa, that's creative; I don't know how I managed to communicate that, but I wasn't trying to communicate that

        If you're trying to learn new syntax, esp if you're working on something already , start a new file (start 10 new files actually), and type it :) that way a year later, you have code you wrote with your own fingertips showing you whats important about that new syntax -- stuff like that you remember :) well I remember

        Hopefully this is clearer (I inglish you not my strong porcupine suit )

        #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; my $str = 'h'; dd $str; ## "h" $str .= 'i'; dd $str; ## "hi" ## one way to write this mini-if aka ternary #~ $str .= 1 > 2 ? '; uh oh 1>2' : '; ok 1<2' ; ## same exact thing, just with more whitespace , easier to read #~ $str .= 1 > 2 #~ ? '; uh oh 1>2' #~ : '; ok 1<2' #~ ;;; ## once again the same exact thing (this time for real) ## the parens provide visual disambiguation ## and not important in this example, also disambiguation for operator + precedence ## $str .= ( 1 > 2 ) ? ( '; uh oh 1>2' ) : ('; ok 1<2'); dd $str; ## "hi; ok 1<2" $str .= do { my $foo = 0; for(1..3){ $foo .= $_; } $foo; ## last statement is like "return $foo;" }; # end of do dd $str; ## "hi; ok 1<20123" __END__ "h" "hi" "hi; ok 1<2" "hi; ok 1<20123"

        porcupine suit aka "armouire" -- ah gess, the pans are mah favreeeet :D

        Use map
        $html .= $cgi->div({-id=>'container'}, $cgi->img({src=>'images/pic.png', height=>'100px', width=>'150px'}), map{$cgi->p($_)}($num..5), $cgi->div({-id=>'menu_bar'},
        poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-11-01 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    If a safe, affordable anti-ageing treatment that extended life indefinitely were to become available, would you take it?



    Results (4 votes), past polls