Mercurial > boosterpack
comparison scripts/pjx_JSON.pl @ 0:477258d09353 boosterpack
[svn r1] initial import
author | robert |
---|---|
date | Sun, 30 Aug 2009 02:19:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:477258d09353 |
---|---|
1 #!C:/strawberry/perl/bin/perl.exe | |
2 use strict; | |
3 use CGI::Ajax; | |
4 use CGI; | |
5 | |
6 my $q = new CGI; | |
7 | |
8 my $Show_Form = sub { | |
9 my $html = ""; | |
10 $html .= <<EOT; | |
11 <HTML> | |
12 <HEAD><title>CGI::Ajax JSON Example</title> | |
13 <script> | |
14 handle_return = function(vv){ | |
15 document.getElementById('object_display').innerHTML = vv; | |
16 eval(vv); // this gives you 'var jsonObj' here in javascript; | |
17 // alert(jsonObj); | |
18 var div = document.getElementById('parsed'); | |
19 div.innerHTML = "</b>key : value<b><br/>"; | |
20 for(var key in jsonObj){ | |
21 div.innerHTML += key + " => " + jsonObj[key] + "<br/>"; | |
22 } | |
23 | |
24 } | |
25 </script> | |
26 </HEAD> | |
27 <BODY> | |
28 <H2> Get The Letter Following the One you Enter </H2> | |
29 <form> | |
30 Enter Number: | |
31 <input type="text" id="val1" size="6" value='abc' onkeyup="json(['val1'], [handle_return]);"> | |
32 <br/><br/>The JavaScript Object:<br/> | |
33 <div id="object_display" style="width:500px;height:200px;"> | |
34 | |
35 </div> | |
36 <br/> After Parsing (use eval) <br/> | |
37 <div id="parsed" style="width:500px;height:200px;"> | |
38 | |
39 </div> | |
40 | |
41 </form> | |
42 </BODY> | |
43 </HTML> | |
44 EOT | |
45 | |
46 return $html; | |
47 }; | |
48 | |
49 my $pjx = CGI::Ajax->new('json' => 'pjx_JSON_out.pl'); | |
50 $pjx->JSDEBUG(1); | |
51 $pjx->DEBUG(1); | |
52 print $pjx->build_html($q,$Show_Form); # this outputs the html for the page |