Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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


in reply to Re^4: 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...I am finding it difficult to generate HTML content with session info, and forward it to Ajax call

Ok, but why post Pseudocode instead of the code you're now trying that is failing for you?

:)Basic debugging checklist , brian's Guide to Solving Any Perl Problem, CGI Help Guide , Troubleshooting Perl CGI scripts, How do I post a question effectively?

  • Comment on Re^5: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.

Replies are listed 'Best First'.
Re^6: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.
by msinfo (Sexton) on Sep 02, 2013 at 01:13 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

        ## $str .= ( 1 > 2 ) ? ( '; uh oh 1>2' ) : ('; ok 1<2'); ## is the same as like if( 1 > 2 ) { $str .= ( '; uh oh 1>2' ); } else { $str .= ( '; ok 1<2' ); }
      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

        Hi monks,

        Anonymous monk, and poj, that was helpful, and below is code, which worked

        $html .= $cgi->div({-id=>'container'}, $cgi->img({src=>'images/pic.png', height=>'100px', + width=>'150px'}), ( do { for(1..3){ $foo .= $_ } $foo ## last statement is like "return $foo;" } # end of do ), $cgi->div(

        I took some time to meditate (or staring ;-)), on Perl Documentation (perldoc perl), and things started to make sense.

        Thanks again! and I am back to meditation ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found