Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by poj (Priest)
on Sep 01, 2013 at 16:03 UTC ( #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


Comment on Re: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.
Select or Download Code
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
Node Status?
node history
Node Type: note [id://1051825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-11-23 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (132 votes), past polls