Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Using Perl, jQuery, and JSON for Web development

by bradcathey (Prior)
on Jun 02, 2010 at 12:56 UTC ( #842754=perltutorial: 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: perltutorial [id://842754]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (15)
As of 2014-09-02 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (29 votes), past polls