Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^3: How do I mix up Perl and jQuery (for beginners)

by poj (Prior)
on Aug 22, 2013 at 10:26 UTC ( #1050506=note: print w/replies, xml ) Need Help??

in reply to Re^2: How do I mix up Perl and jQuery (for beginners)
in thread How do I mix up Perl and jQuery (for beginners)

Here's a very simple demo of an auto-complete input field using html/mysql/json

HTML file
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>autocomplete demo</title> <link rel="stylesheet" href=" +moothness/jquery-ui.css"> <script src=""></script> <script src=""></script> </head> <body> <label for="autocomplete">Select : </label> <input id="autocomplete"> <script> $( "#autocomplete" ).autocomplete({ source: "http://localhost/test/data.cgi", }); </script> </body> </html>
data.cgi to provide data
#!/usr/bin/perl use CGI; use DBI; use JSON; my $dbh = get_dbh(); # your connect details # test data $dbh->do('CREATE TEMPORARY TABLE json ( col1 char(3))'); for ("ABC", "BCD", "CDE", "DEF", "EFG", "FGH", "GHI"){ $dbh->do('INSERT INTO json VALUES (?)',undef,$_); } # query database my $q = CGI->new(); my $sth = $dbh->prepare('SELECT * FROM json WHERE col1 like ?'); $sth->execute('%'.$q->param('term').'%'); my @data=(); while ( my @f = $sth->fetchrow_array){ push @data,$f[0]; } print "Content-type: application/json; charset=iso-8859-1\n\n"; print JSON::to_json(\@data);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1050506]
[TCLion]: Good Morning Monks, I am parsing logs and some date time formats are inconsistent. I am trying to make output all same format. What is the best way to convert a month(word) to month(number)?
[Corion]: TCLion: I'm not aware of a better way than manually building the hash, as all strptime incarnations I know have nasty edge cases

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2017-03-23 14:38 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (287 votes). Check out past polls.