Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by poj (Abbot)
on Sep 01, 2013 at 16:03 UTC ( [id://1051825]=note: print w/replies, xml ) Need Help??


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

The Show_HTML sub should return the html, not print it.
It is not mandatory to use a here-doc, you could built it up like this ;
sub Show_HTML { my $html = $cgi->start_html(); $html .= $cgi->p('Enter something'); $html .= $cgi->input( {-type=>'text', -name=>"va1",-id=>"val1", onkeyup=>"exported_func( ['val1'], ['resultdiv'] );"} ); $html .= $cgi->br; $html .= $cgi->div( {-id=>"resultdiv"} ); $html .= $cgi->end_html(); return $html; }
poj

Replies are listed 'Best First'.
Re^2: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.
by msinfo (Sexton) on Sep 01, 2013 at 17:53 UTC

    Thanks poj

    The Show_HTML sub should return the html, not print it

    I learned that from you.

    The error message goes away, when I use code format shown by you. But, when conditional statement is inserted, in between, it fails. Error says - problem at if condition. When I remove if condition, all goes well.

    my $html = $session->header(); $html .= $cgi->start_html(-charset=>'UTF-8',-style => {'src' => 'sty +lesheet/style.css'}); $html .= $cgi->div({-id=>'container'}, $cgi->img({src=>'images/pic.png', height=>'100px', + width=>'150px'}), if ($cgi->p(($session->is_expired) || ($session->i +s_empty)) =1) { $cgi->p("logged") }, $cgi->div(

      Doctor Doctor it hurts when I do this, but it doesn't hurt when I don't do it

      Ok then :)

        ;-) If it's not humor, then, I didn't understand

        So can other Perl statements be inserted into above code?

      Put the conditional outside the div ;
      my $msg = ($session->is_expired || $session->is_empty) ? 'logged':''; $html .= $cgi->div({-id=>'container'}, $cgi->img({src=>'images/pic.png', height=>'100px',width=>'150px'}), $cgi->p($msg),$cgi->div(
      poj

        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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found