view scripts/pjx_loading.pl @ 10:3b52ac950753 boosterpack tip

going to try to fix this thing
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 17:24:06 -0400
parents 477258d09353
children
line wrap: on
line source
1 #!C:/strawberry/perl/bin/perl.exe
3 use strict;
4 use CGI::Ajax;
5 use CGI;
7 my $func = sub {
8 my $input = shift;
9 my $i=6000000;
10 while($i--){ }
11 return "got input: $input " . 'done';
12 };
15 sub Show_HTML {
16 my $html = <<EOT;
18 <html>
19 <head><title>CGI::Ajax Example</title>
21 <script type=text/javascript>
22 // these 2 functions provide access to the javascript events. Since
23 // is an object anything here will apply to any div that uses a
24 // cgi::ajx registered function. as a convenience, we send in the id
25 // of the current element (el) below. but that can also be accessed
26 // this.target;
27 // if these are not defined, no problem...
28 pjx.prototype.pjxInitialized = function(el){
29 document.getElementById(el).innerHTML = 'Loading';
30 document.getElementById(el).style.backgroundColor = '#ccc';
31 }
33 pjx.prototype.pjxCompleted = function(el){
34 // here we use this.target:
35 // since this is a prototype function, we have access to all of hte
36 // pjx obejct properties.
37 document.getElementById(this.target).style.backgroundColor = '#fff';
38 }
40 </script>
41 </head>
42 <body>
43 <form>
44 Enter Something:&nbsp;
45 <input type="text" name="val1" id="val1" size="6" onkeyup="jsfunc( ['val1'], 'result' ); return true;"><br>
46 Enter Something:&nbsp;
47 <input type="text" name="val2" id="val2" size="6" onkeyup="jsfunc( ['val2'], 'another' ); return true;"><br>
48 <hr>
49 <div id="result" style="border: 1px solid black;
50 width: 440px; height: 80px; overflow: auto">
51 </div>
53 <div id="another" style="border: 1px solid black;
54 width: 440px; height: 80px; overflow: auto">
55 </div>
56 </form>
57 </body>
58 </html>
60 EOT
62 }
64 my $cgi = new CGI(); # create a new CGI object
65 my $pjx = new CGI::Ajax( 'jsfunc' => $func );
66 print $pjx->build_html($cgi,\&Show_HTML);