AJAX programs

From JmPm

Revision as of 17:30, 18 March 2007 by Amire80 (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search
exltst-a16(9) >>pwd
/exlibris/aleph/u16_9/alephe/apache/htdocs
exltst-a16(9) >>more 1_simple_html.htm 5_form.htm 6_javaSctipt.htm 7_ajax.htm 7_ajax.js 8_ajax_with_wget.htm
::::::::::::::
1_simple_html.htm
::::::::::::::
<HTML>
  <HEAD>
  </HEAD>
  <BODY>
    Regular
    <BR>
    <B>Bold</B>
  </BODY>
</HTML>
::::::::::::::
5_form.htm
::::::::::::::

<FORM action="http://62.219.82.138:8991/cgi-bin/4_cgi_pm" method="POST">
  <INPUT NAME="arg1">
  <INPUT TYPE=SUBMIT>
</FORM>
::::::::::::::
6_javaSctipt.htm
::::::::::::::
<HTML>
  <HEAD>
        <script>
            function show(input) {
               document.getElementById("span1").innerHTML = input;
            }
        </script>
  </HEAD>
  <BODY>
    <form>
        <input type="text" id="arg1" onkeyup="show(this.value)">
    </form>
    <br>
    Before <div id="span1"> empty </div> after.

<script src="http://gmodules.com/ig/ifr?url=http://www.schulz.dk/pacman.xml&synd=open&w=300&h=380&title=PacMan+v
2.0&border=%23ffffff%7C0px%2C1px+solid+%2382CAFA%7C0px%2C2px+solid+%23BDEDFF%7C0px%2C3px+solid+%23E0FFFF&output=
js"></script>
  </BODY>
</HTML>
::::::::::::::
7_ajax.htm
::::::::::::::
<html>
<head>
  <script src="http://62.219.82.138:8991/7_ajax.js"></script>
</head>
<body>

   txt1:     <INPUT type="text" id="txt1" onkeyup="sendInfo()">
<br>
   txtHint:  <SPAN id="txtHint">    </SPAN>

</body>
</html>
::::::::::::::
7_ajax.js
::::::::::::::
var xmlHttp

  function sendInfo()
  {
    var txt1     =document.getElementById("txt1")
    showHint("?q=" + txt1.value)
  }

function showHint(str)
{
        if (str.length==0)
        {
                document.getElementById("txtHint").innerHTML=""
                return
        }
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
                alert ("Browser does not support HTTP Request")
                return
        }
        var url="http://62.219.82.138:8991/cgi-bin/7_ajax.pl"
        url=url+str
        url=url+"&sid="+Math.random()
        //alert("the URL is:  " + url)
        xmlHttp.onreadystatechange=stateChanged
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
}

function stateChanged()
{
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
                document.getElementById("txtHint").innerHTML=xmlHttp.responseText
        }
}

function GetXmlHttpObject()
{
        var objXMLHttp=null
        if (window.XMLHttpRequest)
        {
                objXMLHttp=new XMLHttpRequest()
        }
        else if (window.ActiveXObject)
        {
                objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
        return objXMLHttp
}
::::::::::::::
8_ajax_with_wget.htm
::::::::::::::
<html>
<head>
 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
 <script src="http://62.219.82.138:8991/clienthint.js"></script>
</head>
<body>
<FORM>
     <select name=scan_code id="scan_code">
       <option value=TIT               >��×�¨ ��×��� �... (��� �� �����¢�)</option>
       <option value=AUT               >����¨ ��×��� �... (�©��)</option>
       <option value=SUB               >� ��©� ��×��� �...</option>
       <option value=SRS               >�©� �... (��� �� �����¢�)</option>
       <option value=PUB               >��"� ������ �...</option>
       <option value=082               >082</option>
     </select>
<br>
        Type something:
        <INPUT type="text" id="txt1" onkeyup="sendInfo()">
</FORM>
<p>Suggestions:<br>
        <span id="txtHint"></span>
</p>
</body>
</html>









exltst-a16(9) >>pwd
/exlibris/aleph/u16_9/alephe/apache/cgi-bin
exltst-a16(9) >>more 2_cgi_perl 2_cgi_c.c 2_cgi_Cshell 3_perl_with_arg 4_cgi_pm 7_ajax.pl 8_ajax_pm.pl
::::::::::::::
2_cgi_perl
::::::::::::::
#!/exlibris/aleph/a16_9/product/bin/perl
print "Content-Type: text/plain\n\n\n";
print '<HTML><HEAD></HEAD><BODY>',"\n";

(my $SEC, my $MIN, my $HOUR, my $DAY,my $MONTH,my $YEAR) =
             (localtime)[0,1,2,3,4,5]; $MONTH+=1; $YEAR+=1900;
my $now = sprintf("%04d%02d%02d %02d:%02d:%02d",$YEAR,$MONTH,$DAY,$HOUR,$MIN,$SEC);

print "Now its: $now";

print '</BODY></HTML>';
::::::::::::::
2_cgi_c.c
::::::::::::::
#include <stdio.h>
int main()
{
printf ("Content-Type: text/plain\n\n\n");
printf ("Hi world\n");
return 0;
}
::::::::::::::
2_cgi_Cshell
::::::::::::::
#!/bin/csh -f
cat <<END
Content-Type: text/plain


END
echo "Argument:"$QUERY_STRING
::::::::::::::
3_perl_with_arg
::::::::::::::
#!/exlibris/aleph/a16_9/product/bin/perl
print "Content-Type: text/plain\n\n\n";
print '<HTML><HEAD></HEAD><BODY>',"\n";

my $in;
if ($ENV{'REQUEST_METHOD'} eq "GET") {
        $in = $ENV{'QUERY_STRING'};
} else {
        $in = <STDIN>;
}
$in =~ s/\+/ /g;
$in =~ s/%(..)/pack("c",hex($1))/ge;
$in =~ s/\'/`/g;
$in =~ s/\"/`/g;
my @strarr;
@strarr = split("&",$in);
my @strarr2;
my %h; my %h_b;
for (my $c=0;$c<12;$c++) {
        @strarr2 = split(/=/,$strarr[$c]);
        $h{@strarr2[0]}=@strarr2[1];
}

print $h{'arg1'};
print '</BODY></HTML>';
::::::::::::::
4_cgi_pm
::::::::::::::
#!/exlibris/aleph/a16_9/product/bin/perl
# can be viewed in http://62.219.82.138:8991/cgi-bin/4_cgi_pm
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q=new CGI;
print $q->header;

print '<HTML><HEAD></HEAD><BODY>',"\n";
print '<B>Param:</B>',"\n";
print $q->param('arg1'),"\n";

print '</BODY></HTML>';
::::::::::::::
7_ajax.pl
::::::::::::::
#!/exlibris/aleph/a16_9/product/bin/perl
# try at: http://62.219.82.138:8991/cgi-bin/7_ajax.pl?q=a
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $qq=new CGI;
   print $qq->header(-charset=>'utf-8');

# get the q parameter from URL
my $q = $qq->param('q');
#print "-- $q --";  exit;

# Fill up array with names
my @a = qw(
    Anna   Amanda  Brittany  Diana  Doris Cinderella Eva
    Gunda Hege Inga Johanna Kitty Linda Nina Ophelia Fiona
    Petunia Amanda Raquel Cindy Doris Eve Evita Sunniva
    Tove Unni Violet Liza Elizabeth Ellen Wenche Vicky
);
my $len = @a;

# lookup all hints from array if length of q>0
my $hint;
if (length($q) > 0)
{
  $hint="";
  for(my $i=0; $i<$len; $i++)
  {
  if (lc($q) eq lc(substr($a[$i],0,length($q))))
    {
    if ($hint eq "")
      {
      $hint=$a[$i];
      }
    else
      {
      $hint=$hint." , ".$a[$i];
      }
    }
  }
}

# Set output to "no suggestion" if no hint where found
# or to the correct values
my $response;
if ($hint eq "") {
        $response="no suggestion";
} else {
        $response=$hint;
}

# output the response
print $response;

::::::::::::::
8_ajax_pm.pl
::::::::::::::
#!/exlibris/aleph/a16_9/product/bin/perl
  use strict;
  use CGI;      # or any other CGI:: form handler/decoder
  use Ajax;

  my $cgi = new CGI;
  my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func );

  print $pjx->build_html( $cgi, \&Show_HTML);

  sub perl_func {
    my $input = shift;
        $input =~ s/a/_/g;   # do something with $input
    my $output = $input . " was the input while replacing a with _";
    return( $output );
  }

  sub Show_HTML {
    my $html = <<EOHTML;
    <HTML>
      Enter something:
        <input type="text" name="val1" id="val1"
         onkeyup="exported_func( ['val1'], ['resultdiv'] );">
      <br>
      <div id="resultdiv"> </div><br>
    </HTML>
EOHTML
    return $html;
  }


Personal tools