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

RFC:Tutorial: Using jQuery, Json, and Perl for Web development

by bradcathey (Prior)
on May 29, 2010 at 03:19 UTC ( #842126=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    <script type="text/javascript">
       $(function(){
          $(".ethnicity").click(function(){
    ...
            $.getJSON('menu.cgi',
                { rm:'g', ethnicity:$(this).val() },
             ....
    
  2. or download this
    my $stmt = qq~SELECT id, entrees FROM menu WHERE ethnicity = ?~;
                    
    my $entrees = $self->dbh->selectall_arrayref($stmt, {Slice => {}}, $se
    +lf->query->param('ethnicity'));
        
    return $self->json_body( $entrees); #using CGI::App::Plugin::JSON
    
  3. or download this
    function(result){ 
    // returns: [{"entrees":"Lasagna","id":"1"},{"entrees":"Spaghetti","id
    +":"2"},{"entrees":"Pizza","id":"3"}]
    ...
       }
       $('#entree').html(options);
    
  4. or download this
                
    $('#menu').submit(function() {
             
    ...
       });
       return false;
    });
    
  5. or download this
    sub save_form {
       my $self = shift;
    ...
          my $result = [{ 'messages' => $self->param('error_list') }];
          return $self->json_body( $result );
       }
    
  6. or download this
    $.ajax({                
       type: "POST",
    ...
          }
       });
    
  7. or download this
    $self->record();
       
    ...
      
    my $result = [{ 'messages' => $self->param('success_list') }];
    return $self->json_body( $result);  
    
  8. or download this
       if (success) {            
          $('#'+form).resetForm();//jquery.form.js feature
    ...
          $('#'+msgdiv).css('display','block'); //display the success
          $('#'+msgdiv).append(success); //  div and message
       }
    
  9. or download this
    <!--include common header for all pages -->
    <tmpl_include header.tmpl>
    ...
    </script> 
    <!--pull in a standard footer for all pages -->
    <tmpl_include footer.tmpl>
    
  10. or download this
       //called in HTML <head> with:
       //<script type="text/javascript" src="forms.js"></script> 
    ...
             $('#'+msgdiv).append(success); //  div and message
          }
       }
    
  11. or download this
    #--- Get entrees on the fly
    sub get_entrees {
    ...
        
       return $self->json_body( $entrees);
    }
    
  12. or download this
    use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);
    use CGI::Application::Plugin::JSON ':all';
    ...
       $self->dbh->do( $stmt, undef, values %sql);                        
    +         
       $self->param('success_list' => [{'success' => 'Record added'}]);
    }
    
  13. or download this
    use Email::Valid;
    
    ...
         return $value;
       }
    }
    
  14. or download this
    .form {
       float: left;
    ...
       color: green;
       background: url(/images/success.png) no-repeat 5px;
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://842126]
Approved by Old_Gray_Bear
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-07-07 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls