tultalk has asked for the wisdom of the Perl Monks concerning the following question:
Hi
How do I capture the JSON data in a usable manner?
Thanks
Following code executes the CGI script:
<script type="text/javascript"> $(document).ready(function(){ alert("entered function"); $.getJSON("http://www.xxx.org/httpsdocs/cgi-bin/update_tables.cgi?ac +tion=updatetable_167&kind=0&searchterm=19", function(data){ $.each(data, function(key, value){ document.write(key+":"+value+"<br />"); }); }); }); </script
Nothing printed out
Below is log showing that the query was executed and returned the correct values
[Tue Mar 20 19:59:06 2018] update_tables.cgi: searchterm = '19' at upd +ate_tables.cgi line 439. sortindex = '0' at update_tables.cgi line 455. [Tue Mar 20 19:59:06 2018] update_tables.cgi: sortindex = '0' at upda +te_tables.cgi line 455. searchfield = 'user_id' at update_tables.cgi line 457. [Tue Mar 20 19:59:06 2018] update_tables.cgi: searchfield = 'user_id' + at update_tables.cgi line 457. statement = 'SELECT * FROM users WHERE user_id = ? ORDER BY ? ASC' at + update_tables.cgi line 462. count = '1' at update_tables.cgi line 473. [Tue Mar 20 19:59:06 2018] update_tables.cgi: count = '1' at update_ta +bles.cgi line 486. Finished print {"DD":"2019-01-30","DP":"2018-12-31","MD":"120.00","MJ" +:"2018-01-30","address1":"1471 Meeks Rd","address2":null,"business":" +JZ Electroplating","city":"Latham","comments":"This is a test entry", +"email":"jze@yahoo.com","forename":"John","id":57,"lastname":"Zinzer" +,"password":"1234","phone_cell":"517-204-1111","phone_home":"517-233- +4378","pin":"JbwmZ","position":"General Member","state":"NJ","user_id +":19,"username":"lms19","zip":"45789-2334"} at update_tables.cgi line + 492.
JSON print works as I captured output in an IFrame for testing.
my $searchResult = $sth->fetchrow_hashref(); my $count = $sth->rows; warn("count = '$count'"); if ($count == 0) { warn("Failed Search: '$searchfield' equal to '$searchterm' "); my %searchFail = ( SearchError => $kind); my $json = JSON->new; $json->canonical(1); $json = encode_json(\%searchFail); print "Content-Type: application/json\n\n"; print $json; warn("Finished print 0 count $json"); exit(1); } #{"SearchError":0} Good else { warn("count = '$count'"); my $json = JSON->new; $json->canonical(1); $json = encode_json($searchResult); print "Content-Type: application/json\n\n"; print $json; warn("Finished print $json"); exit(0); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: JSON Return Values
by NetWallah (Canon) on Mar 21, 2018 at 04:56 UTC | |
by tultalk (Monk) on Mar 21, 2018 at 09:43 UTC | |
by tultalk (Monk) on Mar 21, 2018 at 10:27 UTC | |
by tultalk (Monk) on Mar 21, 2018 at 10:42 UTC | |
by tultalk (Monk) on Mar 21, 2018 at 13:07 UTC | |
by tultalk (Monk) on Mar 22, 2018 at 14:58 UTC | |
by Corion (Patriarch) on Mar 22, 2018 at 15:07 UTC | |
by tultalk (Monk) on Mar 22, 2018 at 17:35 UTC | |
by tultalk (Monk) on Mar 22, 2018 at 15:42 UTC | |
by tultalk (Monk) on Mar 23, 2018 at 16:47 UTC | |
|
Re: JSON Return Values
by karlgoethebier (Abbot) on Mar 21, 2018 at 17:52 UTC | |
|
Re: JSON Return Values
by tultalk (Monk) on Mar 23, 2018 at 17:08 UTC | |
by poj (Abbot) on Mar 23, 2018 at 19:38 UTC | |
by tultalk (Monk) on Mar 23, 2018 at 20:27 UTC | |
|
Re: JSON Return Values
by Anonymous Monk on Mar 21, 2018 at 13:22 UTC | |
by Your Mother (Archbishop) on Mar 21, 2018 at 14:17 UTC | |
by tultalk (Monk) on Mar 22, 2018 at 10:50 UTC |