#!/usr/bin/perl -w use strict; $| = 1; ############################################### # Location: # http://www.infocopter.com/perl/ajax.html ############################################### use CGI::Ajax; use CGI; my $q = CGI->new(); ##### GLOBAL my $Google_pattern_l = q~http://www.google.ch/custom?domains=www.infocopter.com&q=~; my $Google_pattern_r = q~&sitesearch=www.infocopter.com&sa=Suchen&client=pub-2462448779608523&forid=1&channel=7029886459&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%239A2C06%3BGL%3A1%3BDIV%3A%2333FFFF%3BVLC%3AD03500%3BAH%3Acenter%3BBGC%3AFFFFCC%3BLBGC%3AE6E6E6%3BALC%3A440066%3BLC%3A440066%3BT%3A336699%3BGFNT%3A223472%3BGIMP%3A223472%3BLH%3A25%3BLW%3A106%3BL%3Ahttp%3A%2F%2Fwww.infocopter.com%2Fimages%2Flogo-ic-vsma.gif%3BS%3Ahttp%3A%2F%2F%3BFORID%3A1%3B&hl=de~; my $Show_Form = sub { my $html = ''; $html = q~ Ajax Demo You are here iC Home > Perl > Documentation > Ajax > Demo

Ajax Demo

Input: Try: foo or reto

~; $html; }; &main(); sub main() { my $search_fx = sub { my $in = shift || '* no val *'; my $html = ''; return $html if length($in) < 2; my $ret = ''; open(IN, ') { if ($_ =~ /$in/i) { chomp; my ($key, $val) = split /\t/; (my $qsafe_val = &uri_escape($val)) =~ s/%/%25/g; # keep '%' $ret .= qq~$key → $val
~; } } close IN; $html .= $ret ? 'Found results:
' . $ret : ''; $html .= q~
Ajax Link Search~; $html; }; my $pjx = CGI::Ajax->new( search => $search_fx, ); $pjx->JSDEBUG(0); $pjx->DEBUG(0); print $pjx->build_html($q, $Show_Form); # this outputs the html for the page } sub uri_escape { my $text = $_[0]; # Build a char to hex map my %escapes = (); for (0..255) { $escapes{chr($_)} = sprintf("%%%02X", $_); } # Default unsafe characters. RFC 2732 ^(uric - reserved) $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g; $text; }