Mercurial > boosterpack
diff scripts/pjx_JSON.pl @ 0:477258d09353 boosterpack
[svn r1] initial import
author | robert |
---|---|
date | Sun, 30 Aug 2009 02:19:26 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/scripts/pjx_JSON.pl Sun Aug 30 02:19:26 2009 -0400 1.3 @@ -0,0 +1,52 @@ 1.4 +#!C:/strawberry/perl/bin/perl.exe 1.5 +use strict; 1.6 +use CGI::Ajax; 1.7 +use CGI; 1.8 + 1.9 +my $q = new CGI; 1.10 + 1.11 +my $Show_Form = sub { 1.12 + my $html = ""; 1.13 + $html .= <<EOT; 1.14 +<HTML> 1.15 +<HEAD><title>CGI::Ajax JSON Example</title> 1.16 +<script> 1.17 + handle_return = function(vv){ 1.18 + document.getElementById('object_display').innerHTML = vv; 1.19 + eval(vv); // this gives you 'var jsonObj' here in javascript; 1.20 +// alert(jsonObj); 1.21 + var div = document.getElementById('parsed'); 1.22 + div.innerHTML = "</b>key : value<b><br/>"; 1.23 + for(var key in jsonObj){ 1.24 + div.innerHTML += key + " => " + jsonObj[key] + "<br/>"; 1.25 + } 1.26 + 1.27 + } 1.28 +</script> 1.29 +</HEAD> 1.30 +<BODY> 1.31 +<H2> Get The Letter Following the One you Enter </H2> 1.32 +<form> 1.33 + Enter Number: 1.34 +<input type="text" id="val1" size="6" value='abc' onkeyup="json(['val1'], [handle_return]);"> 1.35 +<br/><br/>The JavaScript Object:<br/> 1.36 +<div id="object_display" style="width:500px;height:200px;"> 1.37 + 1.38 +</div> 1.39 +<br/> After Parsing (use eval) <br/> 1.40 +<div id="parsed" style="width:500px;height:200px;"> 1.41 + 1.42 +</div> 1.43 + 1.44 +</form> 1.45 +</BODY> 1.46 +</HTML> 1.47 +EOT 1.48 + 1.49 + return $html; 1.50 +}; 1.51 + 1.52 +my $pjx = CGI::Ajax->new('json' => 'pjx_JSON_out.pl'); 1.53 +$pjx->JSDEBUG(1); 1.54 +$pjx->DEBUG(1); 1.55 +print $pjx->build_html($q,$Show_Form); # this outputs the html for the page