view BoosterPack/scripts/.svn/text-base/pjx_JSON.pl.svn-base @ 0:0d795f02a8bb tip

initial committ. what was I thinking?
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 16:57:26 -0400
parents
children
line wrap: on
line source
1 #!C:/strawberry/perl/bin/perl.exe
2 use strict;
3 use CGI::Ajax;
4 use CGI;
6 my $q = new CGI;
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 }
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;">
35 </div>
36 <br/> After Parsing (use eval) <br/>
37 <div id="parsed" style="width:500px;height:200px;">
39 </div>
41 </form>
42 </BODY>
43 </HTML>
44 EOT
46 return $html;
47 };
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